Merge branch 'fc/completion-zsh' into maint
[gitweb.git] / write_or_die.c
index e125e11d3b63e3dab9077d7b414e83e7ff7d16ad..d45b536021e15c5a674f7969be39f238194bef99 100644 (file)
@@ -34,48 +34,22 @@ void maybe_flush_or_die(FILE *f, const char *desc)
                        return;
        }
        if (fflush(f)) {
-               if (errno == EPIPE)
+               /*
+                * On Windows, EPIPE is returned only by the first write()
+                * after the reading end has closed its handle; subsequent
+                * write()s return EINVAL.
+                */
+               if (errno == EPIPE || errno == EINVAL)
                        exit(0);
-               die("write failure on %s: %s", desc, strerror(errno));
-       }
-}
-
-int read_in_full(int fd, void *buf, size_t count)
-{
-       char *p = buf;
-       ssize_t total = 0;
-
-       while (count > 0) {
-               ssize_t loaded = xread(fd, p, count);
-               if (loaded <= 0)
-                       return total ? total : loaded;
-               count -= loaded;
-               p += loaded;
-               total += loaded;
+               die_errno("write failure on '%s'", desc);
        }
-
-       return total;
 }
 
-int write_in_full(int fd, const void *buf, size_t count)
+void fsync_or_die(int fd, const char *msg)
 {
-       const char *p = buf;
-       ssize_t total = 0;
-
-       while (count > 0) {
-               ssize_t written = xwrite(fd, p, count);
-               if (written < 0)
-                       return -1;
-               if (!written) {
-                       errno = ENOSPC;
-                       return -1;
-               }
-               count -= written;
-               p += written;
-               total += written;
+       if (fsync(fd) < 0) {
+               die_errno("fsync error on '%s'", msg);
        }
-
-       return total;
 }
 
 void write_or_die(int fd, const void *buf, size_t count)
@@ -83,7 +57,7 @@ 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);
-               die("write error (%s)", strerror(errno));
+               die_errno("write error");
        }
 }