GIT 1.4.4-rc2
[git/gitweb.git] / write_or_die.c
blobbfe4eeb6494c7076bf7f319cf11628f586142aa5
1 #include "cache.h"
3 void write_or_die(int fd, const void *buf, size_t count)
5 const char *p = buf;
6 ssize_t written;
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));
17 count -= written;
18 p += written;
22 int write_or_whine(int fd, const void *buf, size_t count, const char *msg)
24 const char *p = buf;
25 ssize_t written;
27 while (count > 0) {
28 written = xwrite(fd, p, count);
29 if (written == 0) {
30 fprintf(stderr, "%s: disk full?\n", msg);
31 return 0;
33 else if (written < 0) {
34 if (errno == EPIPE)
35 exit(0);
36 fprintf(stderr, "%s: write error (%s)\n",
37 msg, strerror(errno));
38 return 0;
40 count -= written;
41 p += written;
44 return 1;