chiark / gitweb /
util: loop_write - accept 0-length message
authorTom Gundersen <teg@jklm.no>
Fri, 15 May 2015 23:07:45 +0000 (01:07 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 08:57:15 +0000 (09:57 +0100)
write() can send empty messages, so make sure loop_write() can do the same.

src/shared/util.c

index d7a5b20946d886588e9a8541688f6bfd8cde1d6f..d3dacfcfb5300b0d55eb439273c277f2f7c0f0a5 100644 (file)
@@ -1665,7 +1665,7 @@ int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
 
         errno = 0;
 
-        while (nbytes > 0) {
+        do {
                 ssize_t k;
 
                 k = write(fd, p, nbytes);
@@ -1685,12 +1685,12 @@ int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
                         return -errno;
                 }
 
-                if (k == 0) /* Can't really happen */
+                if (nbytes > 0 && k == 0) /* Can't really happen */
                         return -EIO;
 
                 p += k;
                 nbytes -= k;
-        }
+        } while (nbytes > 0);
 
         return 0;
 }