summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--write_or_die.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/write_or_die.c b/write_or_die.c
index a119e1d208..7f99a22aed 100644
--- a/write_or_die.c
+++ b/write_or_die.c
@@ -37,15 +37,14 @@ int write_in_full(int fd, const void *buf, size_t count)
{
const char *p = buf;
ssize_t total = 0;
- ssize_t written = 0;
while (count > 0) {
- written = xwrite(fd, p, count);
- if (written <= 0) {
- if (total)
- return total;
- else
- return written;
+ size_t written = xwrite(fd, p, count);
+ if (written < 0)
+ return -1;
+ if (!written) {
+ errno = ENOSPC;
+ return -1;
}
count -= written;
p += written;