2 #include "run-command.h"
4 static void check_pipe(int err)
10 signal(SIGPIPE, SIG_DFL);
12 /* Should never happen, but just in case... */
18 * Some cases use stdio, but want to flush after the write
19 * to get error handling (and to get better interactive
20 * behaviour - not buffering excessively).
22 * Of course, if the flush happened within the write itself,
23 * we've already lost the error code, and cannot report it any
24 * more. So we just ignore that case instead (and hope we get
25 * the right error code on the flush).
27 * If the file handle is stdout, and stdout is a file, then skip the
28 * flush entirely since it's not needed.
30 void maybe_flush_or_die(FILE *f, const char *desc)
32 static int skip_stdout_flush = -1;
37 if (skip_stdout_flush < 0) {
38 cp = getenv("GIT_FLUSH");
40 skip_stdout_flush = (atoi(cp) == 0);
41 else if ((fstat(fileno(stdout), &st) == 0) &&
43 skip_stdout_flush = 1;
45 skip_stdout_flush = 0;
47 if (skip_stdout_flush && !ferror(f))
52 die_errno("write failure on '%s'", desc);
56 void fprintf_or_die(FILE *f, const char *fmt, ...)
62 ret = vfprintf(f, fmt, ap);
67 die_errno("write error");
71 void fsync_or_die(int fd, const char *msg)
74 die_errno("fsync error on '%s'", msg);
78 void write_or_die(int fd, const void *buf, size_t count)
80 if (write_in_full(fd, buf, count) < 0) {
82 die_errno("write error");
86 int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg)
88 if (write_in_full(fd, buf, count) < 0) {
90 fprintf(stderr, "%s: write error (%s)\n",
91 msg, strerror(errno));