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)
+ssize_t read_in_full(int fd, void *buf, size_t count)
{
char *p = buf;
ssize_t total = 0;
return total;
}
-int write_in_full(int fd, const void *buf, size_t count)
+ssize_t write_in_full(int fd, const void *buf, size_t count)
{
const char *p = buf;
ssize_t total = 0;
return total;
}
+void fsync_or_die(int fd, const char *msg)
+{
+ if (fsync(fd) < 0) {
+ die("%s: fsync error (%s)", msg, strerror(errno));
+ }
+}
+
void write_or_die(int fd, const void *buf, size_t count)
{
if (write_in_full(fd, buf, count) < 0) {