1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
11 ssize_t FAST_FUNC safe_read(int fd, void *buf, size_t count)
16 n = read(fd, buf, count);
17 if (n >= 0 || errno != EINTR)
19 /* Some callers set errno=0, are upset when they see EINTR.
20 * Returning EINTR is wrong since we retry read(),
21 * the "error" was transient.
24 /* repeat the read() */
31 * Read all of the supplied buffer from a file.
32 * This does multiple reads as necessary.
33 * Returns the amount read, or -1 on an error.
34 * A short read is returned on an end of file.
36 ssize_t FAST_FUNC full_read(int fd, void *buf, size_t len)
44 cc = safe_read(fd, buf, len);
48 /* we already have some! */
49 /* user can do another read to know the error code */
52 return cc; /* read() returns -1 on failure. */
56 buf = ((char *)buf) + cc;
64 ssize_t FAST_FUNC read_close(int fd, void *buf, size_t size)
67 size = full_read(fd, buf, size);
74 ssize_t FAST_FUNC open_read_close(const char *filename, void *buf, size_t size)
76 int fd = open(filename, O_RDONLY);
79 return read_close(fd, buf, size);