diff --git a/src/shared/util.c b/src/shared/util.c index dda88bd2ee8..3060adc8a65 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; }