Skip to content

Commit

Permalink
Windows: Work around an oddity when a pipe with no reader is written to.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Sixt committed Jun 26, 2008
1 parent bfdd9ff commit b2f5e26
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion write_or_die.c
Expand Up @@ -34,7 +34,12 @@ 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));
}
Expand Down

0 comments on commit b2f5e26

Please sign in to comment.