3 static void check_pipe(int err
)
6 signal(SIGPIPE
, SIG_DFL
);
8 /* Should never happen, but just in case... */
14 * Some cases use stdio, but want to flush after the write
15 * to get error handling (and to get better interactive
16 * behaviour - not buffering excessively).
18 * Of course, if the flush happened within the write itself,
19 * we've already lost the error code, and cannot report it any
20 * more. So we just ignore that case instead (and hope we get
21 * the right error code on the flush).
23 * If the file handle is stdout, and stdout is a file, then skip the
24 * flush entirely since it's not needed.
26 void maybe_flush_or_die(FILE *f
, const char *desc
)
28 static int skip_stdout_flush
= -1;
33 if (skip_stdout_flush
< 0) {
34 cp
= getenv("GIT_FLUSH");
36 skip_stdout_flush
= (atoi(cp
) == 0);
37 else if ((fstat(fileno(stdout
), &st
) == 0) &&
39 skip_stdout_flush
= 1;
41 skip_stdout_flush
= 0;
43 if (skip_stdout_flush
&& !ferror(f
))
48 die_errno("write failure on '%s'", desc
);
52 void fprintf_or_die(FILE *f
, const char *fmt
, ...)
58 ret
= vfprintf(f
, fmt
, ap
);
63 die_errno("write error");
67 void fsync_or_die(int fd
, const char *msg
)
70 die_errno("fsync error on '%s'", msg
);
74 void write_or_die(int fd
, const void *buf
, size_t count
)
76 if (write_in_full(fd
, buf
, count
) < 0) {
78 die_errno("write error");
82 int write_or_whine_pipe(int fd
, const void *buf
, size_t count
, const char *msg
)
84 if (write_in_full(fd
, buf
, count
) < 0) {
86 fprintf(stderr
, "%s: write error (%s)\n",
87 msg
, strerror(errno
));
94 int write_or_whine(int fd
, const void *buf
, size_t count
, const char *msg
)
96 if (write_in_full(fd
, buf
, count
) < 0) {
97 fprintf(stderr
, "%s: write error (%s)\n",
98 msg
, strerror(errno
));