summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-05-16 01:07:45 +0200
committerTom Gundersen <teg@jklm.no>2015-05-16 01:14:48 +0200
commit8c7e28a191709f90736054e6f7844cf35b4ab93d (patch)
treea4617e8503561266fb72b6bfdc69284f3cba03e2
parent43d60b77a83b3185e37c65c4f2649d24c227c7f0 (diff)
util: loop_write - accept 0-length message
write() can send empty messages, so make sure loop_write() can do the same.
-rw-r--r--src/shared/util.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index dda88bd2ee..3060adc8a6 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -1664,7 +1664,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);
@@ -1684,12 +1684,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;
}