X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=write_or_die.c;h=4c29255df1b637f93ab3d59e0dcab1fa3b40e10b;hb=4886b89f8fde57b76738c96761eecbfbd0b13112;hp=32f99140205f8969d8a884b3cf9448eec3f1dd16;hpb=65ea3b8c6d9517c5d7f2a6c089cc6578c9486114;p=git.git diff --git a/write_or_die.c b/write_or_die.c index 32f991402..4c29255df 100644 --- a/write_or_die.c +++ b/write_or_die.c @@ -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)); } } -ssize_t 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; - } - - return total; -} - -ssize_t 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("%s: fsync error (%s)", msg, strerror(errno)); } - - return total; } void write_or_die(int fd, const void *buf, size_t count)