lib: add sys_read_v - void variant of sys_read
authorMichael Adam <obnox@samba.org>
Fri, 25 Mar 2016 00:28:27 +0000 (01:28 +0100)
committerMichael Adam <obnox@samba.org>
Thu, 12 May 2016 22:16:15 +0000 (00:16 +0200)
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Christian Ambach <ambi@samba.org>
lib/util/sys_rw.c
lib/util/sys_rw.h

index f625066ebccea780c43e4d9466e63998a7254eb9..3962d492714560f2ad313b03a082f93238c4ea7a 100644 (file)
@@ -40,6 +40,22 @@ ssize_t sys_read(int fd, void *buf, size_t count)
        return ret;
 }
 
+/**
+ * read wrapper, void variant:
+ * This is intended to be used as a void variant of
+ * read in situations where the caller wants to ignore
+ * the result. Hence not checking for EAGAIN|EWOULDBLOCK.
+ */
+void sys_read_v(int fd, void *buf, size_t count)
+{
+       ssize_t ret;
+
+       do {
+               ret = read(fd, buf, count);
+       } while (ret == -1 && errno == EINTR);
+}
+
+
 /*******************************************************************
 A write wrapper that will deal with EINTR/EWOULDBLOCK.
 ********************************************************************/
index ee1584e904f64234366e57344287690e88dd3b79..6b708a889284e5be659ba18a157c90274606c1d4 100644 (file)
@@ -28,6 +28,7 @@
 struct iovec;
 
 ssize_t sys_read(int fd, void *buf, size_t count);
+void sys_read_v(int fd, void *buf, size_t count);
 ssize_t sys_write(int fd, const void *buf, size_t count);
 ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt);
 ssize_t sys_pread(int fd, void *buf, size_t count, off_t off);