timestamp_t: a new data type for timestamps
[gitweb.git] / write_or_die.c
index 960f448cffd9ffd4e53763dfed3669bc374b8620..eab8c8d0b9aab55c8435b9f451efd81e715131f8 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "run-command.h"
 
 /*
  * Some cases use stdio, but want to flush after the write
@@ -34,48 +35,37 @@ void maybe_flush_or_die(FILE *f, const char *desc)
                        return;
        }
        if (fflush(f)) {
-               if (errno == EPIPE)
-                       exit(0);
+               check_pipe(errno);
                die_errno("write failure on '%s'", desc);
        }
 }
 
-void fsync_or_die(int fd, const char *msg)
+void fprintf_or_die(FILE *f, const char *fmt, ...)
 {
-       if (fsync(fd) < 0) {
-               die_errno("fsync error on '%s'", msg);
-       }
-}
+       va_list ap;
+       int ret;
 
-void write_or_die(int fd, const void *buf, size_t count)
-{
-       if (write_in_full(fd, buf, count) < 0) {
-               if (errno == EPIPE)
-                       exit(0);
+       va_start(ap, fmt);
+       ret = vfprintf(f, fmt, ap);
+       va_end(ap);
+
+       if (ret < 0) {
+               check_pipe(errno);
                die_errno("write error");
        }
 }
 
-int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg)
+void fsync_or_die(int fd, const char *msg)
 {
-       if (write_in_full(fd, buf, count) < 0) {
-               if (errno == EPIPE)
-                       exit(0);
-               fprintf(stderr, "%s: write error (%s)\n",
-                       msg, strerror(errno));
-               return 0;
+       if (fsync(fd) < 0) {
+               die_errno("fsync error on '%s'", msg);
        }
-
-       return 1;
 }
 
-int write_or_whine(int fd, const void *buf, size_t count, const char *msg)
+void write_or_die(int fd, const void *buf, size_t count)
 {
        if (write_in_full(fd, buf, count) < 0) {
-               fprintf(stderr, "%s: write error (%s)\n",
-                       msg, strerror(errno));
-               return 0;
+               check_pipe(errno);
+               die_errno("write error");
        }
-
-       return 1;
 }