Clarify syntax and role of git-add in status output
[git/jr.git] / write_or_die.c
blob650f13fc012b14a6aaa62534727d4ef9cdce58bd
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;
47 int write_in_full(int fd, const void *buf, size_t count, const char *msg)
49 const char *p = buf;
50 ssize_t written;
52 while (count > 0) {
53 written = xwrite(fd, p, count);
54 if (written == 0) {
55 fprintf(stderr, "%s: disk full?\n", msg);
56 return 0;
58 else if (written < 0) {
59 fprintf(stderr, "%s: write error (%s)\n",
60 msg, strerror(errno));
61 return 0;
63 count -= written;
64 p += written;
67 return 1;