From 73b51e93d2927af2fa9f332f31c25ca2319bd0dd Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Fri, 17 Aug 2007 18:40:36 +0200 Subject: [PATCH] Work around a Windows oddity when a pipe with no reader is written to. The first WriteFile() returns ERROR_BROKEN_PIPE, subsequent WriteFile()s return ERROR_NO_DATA, which is not translated to EPIPE, but EINVAL. Hmpf! --- write_or_die.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/write_or_die.c b/write_or_die.c index e125e11d3b..40b046acb0 100644 --- a/write_or_die.c +++ b/write_or_die.c @@ -34,7 +34,16 @@ void maybe_flush_or_die(FILE *f, const char *desc) return; } if (fflush(f)) { +#ifndef __MINGW32__ if (errno == EPIPE) +#else + /* + * 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) +#endif exit(0); die("write failure on %s: %s", desc, strerror(errno)); }