Skip to content

Commit b2f5e26

Browse files
author
Johannes Sixt
committed
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>
1 parent bfdd9ff commit b2f5e26

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

write_or_die.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ void maybe_flush_or_die(FILE *f, const char *desc)
3434
return;
3535
}
3636
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)
3843
exit(0);
3944
die("write failure on %s: %s", desc, strerror(errno));
4045
}

0 commit comments

Comments
 (0)