diff options
Diffstat (limited to 'write_or_die.c')
-rw-r--r-- | write_or_die.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/write_or_die.c b/write_or_die.c index b50f99a936..49e80aa222 100644 --- a/write_or_die.c +++ b/write_or_die.c @@ -1,8 +1,12 @@ #include "cache.h" +#include "run-command.h" static void check_pipe(int err) { if (err == EPIPE) { + if (in_async()) + async_exit(141); + signal(SIGPIPE, SIG_DFL); raise(SIGPIPE); /* Should never happen, but just in case... */ @@ -49,6 +53,21 @@ void maybe_flush_or_die(FILE *f, const char *desc) } } +void fprintf_or_die(FILE *f, const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vfprintf(f, fmt, ap); + va_end(ap); + + if (ret < 0) { + check_pipe(errno); + die_errno("write error"); + } +} + void fsync_or_die(int fd, const char *msg) { if (fsync(fd) < 0) { |