summaryrefslogtreecommitdiffstats
path: root/include/all-io.h
diff options
context:
space:
mode:
authorPetr Uzel2012-05-15 10:49:02 +0200
committerKarel Zak2012-05-15 11:32:36 +0200
commitf80e9bc30a2ae9032790b888abc6ffc8ca90a940 (patch)
tree0487dfa6dd1dfa954ba652d12af83d2b2430b2ea /include/all-io.h
parentinclude: rename writeall.h to all-io.h (diff)
downloadkernel-qcow2-util-linux-f80e9bc30a2ae9032790b888abc6ffc8ca90a940.tar.gz
kernel-qcow2-util-linux-f80e9bc30a2ae9032790b888abc6ffc8ca90a940.tar.xz
kernel-qcow2-util-linux-f80e9bc30a2ae9032790b888abc6ffc8ca90a940.zip
libuuid: move read_all to include/all-io.h
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
Diffstat (limited to 'include/all-io.h')
-rw-r--r--include/all-io.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/include/all-io.h b/include/all-io.h
index 4d1ae1e53..b79d702bd 100644
--- a/include/all-io.h
+++ b/include/all-io.h
@@ -44,4 +44,29 @@ static inline int fwrite_all(const void *ptr, size_t size,
return 0;
}
+static inline ssize_t read_all(int fd, char *buf, size_t count)
+{
+ ssize_t ret;
+ ssize_t c = 0;
+ int tries = 0;
+
+ memset(buf, 0, count);
+ while (count > 0) {
+ ret = read(fd, buf, count);
+ if (ret <= 0) {
+ if ((errno == EAGAIN || errno == EINTR || ret == 0) &&
+ (tries++ < 5))
+ continue;
+ return c ? c : -1;
+ }
+ if (ret > 0)
+ tries = 0;
+ count -= ret;
+ buf += ret;
+ c += ret;
+ }
+ return c;
+}
+
+
#endif /* UTIL_LINUX_ALL_IO_H */