@matheusbsbs / matheus-bagliano / commits / b2f5e2684d
Fork 0

Windows: Work around an oddity when a pipe with no reader is written to.

On Windows, write() is implemented using WriteFile(). After the reader closed its end of the pipe, the first WriteFile() returns ERROR_BROKEN_PIPE (which translates to EPIPE), subsequent WriteFile()s return ERROR_NO_DATA, which is translated to EINVAL. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>

Johannes Sixt committed Aug 17, 2007 at 18:40 UTC b2f5e2684da060dd821bf90f88df8b6dc9401a40
1 file changed +6 -1
write_or_die.c
+6 -1
@@ -34,7 +34,12 @@ void maybe_flush_or_die(FILE *f, const char *desc)
34 return;
35 }
36 if (fflush(f)) {
37 - if (errno == EPIPE)
37 + /*
38 + * On Windows, EPIPE is returned only by the first write()
39 + * after the reading end has closed its handle; subsequent
40 + * write()s return EINVAL.
41 + */
42 + if (errno == EPIPE || errno == EINVAL)
43 exit(0);
44 die("write failure on %s: %s", desc, strerror(errno));
45 }