From: Johannes Sixt Date: Fri, 17 Aug 2007 16:40:36 +0000 (+0200) Subject: Windows: Work around an oddity when a pipe with no reader is written to. X-Git-Tag: v1.6.0-rc0~159^2~4 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b2f5e2684da060dd821bf90f88df8b6dc9401a40;p=git.git 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 --- diff --git a/write_or_die.c b/write_or_die.c index 630be4cb9..e4c8e225f 100644 --- a/write_or_die.c +++ b/write_or_die.c @@ -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)); }