]> git.ipfire.org Git - thirdparty/git.git/blame - write_or_die.c
Add write_or_die(), a helper function
[thirdparty/git.git] / write_or_die.c
CommitLineData
7230e6d0
RS
1#include "cache.h"
2
3void write_or_die(int fd, const void *buf, size_t count)
4{
5 const char *p = buf;
6 ssize_t written;
7
8 while (count > 0) {
9 written = xwrite(fd, p, count);
10 if (written == 0)
11 die("disk full?");
12 else if (written < 0) {
13 if (errno == EPIPE)
14 exit(0);
15 die("write error (%s)", strerror(errno));
16 }
17 count -= written;
18 p += written;
19 }
20}