diff --git a/src/util/util.c b/src/util/util.c index a2582aad4d782b864f4da0b42d900ec0ade8d215..7b8bf4ab64f7c27a2a280737fab2be63628c8b4c 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -88,42 +88,44 @@ verify(sizeof(gid_t) <= sizeof (unsigned int) && __FUNCTION__, __LINE__, __VA_ARGS__) /* Like read(), but restarts after EINTR */ -int saferead(int fd, void *buf, size_t count) -{ - size_t nread = 0; - while (count > 0) { - ssize_t r = read(fd, buf, count); - if (r < 0 && errno == EINTR) - continue; - if (r < 0) - return r; - if (r == 0) - return nread; - buf = (char *)buf + r; - count -= r; - nread += r; - } - return nread; +ssize_t +saferead(int fd, void *buf, size_t count) +{ + size_t nread = 0; + while (count > 0) { + ssize_t r = read(fd, buf, count); + if (r < 0 && errno == EINTR) + continue; + if (r < 0) + return r; + if (r == 0) + return nread; + buf = (char *)buf + r; + count -= r; + nread += r; + } + return nread; } /* Like write(), but restarts after EINTR */ -ssize_t safewrite(int fd, const void *buf, size_t count) -{ - size_t nwritten = 0; - while (count > 0) { - ssize_t r = write(fd, buf, count); - - if (r < 0 && errno == EINTR) - continue; - if (r < 0) - return r; - if (r == 0) - return nwritten; - buf = (const char *)buf + r; - count -= r; - nwritten += r; - } - return nwritten; +ssize_t +safewrite(int fd, const void *buf, size_t count) +{ + size_t nwritten = 0; + while (count > 0) { + ssize_t r = write(fd, buf, count); + + if (r < 0 && errno == EINTR) + continue; + if (r < 0) + return r; + if (r == 0) + return nwritten; + buf = (const char *)buf + r; + count -= r; + nwritten += r; + } + return nwritten; } #ifdef HAVE_POSIX_FALLOCATE diff --git a/src/util/util.h b/src/util/util.h index a240d8791c7f228160887655d7c8a761f38c4f7d..0385fe18ef64f88500222f2ede5171b0f450a3d3 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -36,7 +36,7 @@ # define MIN(a, b) ((a) < (b) ? (a) : (b)) # endif -int saferead(int fd, void *buf, size_t count) ATTRIBUTE_RETURN_CHECK; +ssize_t saferead(int fd, void *buf, size_t count) ATTRIBUTE_RETURN_CHECK; ssize_t safewrite(int fd, const void *buf, size_t count) ATTRIBUTE_RETURN_CHECK; int safezero(int fd, int flags, off_t offset, off_t len)