diff options
Diffstat (limited to 'write_or_die.c')
-rw-r--r-- | write_or_die.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/write_or_die.c b/write_or_die.c new file mode 100644 index 000000000..ab4cb8a69 --- /dev/null +++ b/write_or_die.c @@ -0,0 +1,20 @@ +#include "cache.h" + +void write_or_die(int fd, const void *buf, size_t count) +{ + const char *p = buf; + ssize_t written; + + while (count > 0) { + written = xwrite(fd, p, count); + if (written == 0) + die("disk full?"); + else if (written < 0) { + if (errno == EPIPE) + exit(0); + die("write error (%s)", strerror(errno)); + } + count -= written; + p += written; + } +} |