diff options
author | Jeff King <peff@peff.net> | 2012-10-25 06:43:01 -0400 |
---|---|---|
committer | Jeff King <peff@peff.net> | 2012-10-25 06:43:01 -0400 |
commit | bbbd0573895f7f79aeb1faa5c0333915947096c0 (patch) | |
tree | bc89be8a152a431c639d1bd389e11910464e4208 /compat | |
parent | 33d3c6bb9bcc10b9aa5e46f66ef516c649b2c703 (diff) | |
parent | 84adb641545f4b58f9276adf099f840ea2928e44 (diff) | |
download | git-bbbd0573895f7f79aeb1faa5c0333915947096c0.tar.gz git-bbbd0573895f7f79aeb1faa5c0333915947096c0.tar.xz |
Merge branch 'js/mingw-fflush-errno'
* js/mingw-fflush-errno:
maybe_flush_or_die: move a too-loose Windows specific error
Diffstat (limited to 'compat')
-rw-r--r-- | compat/mingw.c | 22 | ||||
-rw-r--r-- | compat/mingw.h | 3 |
2 files changed, 25 insertions, 0 deletions
diff --git a/compat/mingw.c b/compat/mingw.c index afc892d6b..4e6383898 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -335,6 +335,28 @@ FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream) return freopen(filename, otype, stream); } +#undef fflush +int mingw_fflush(FILE *stream) +{ + int ret = fflush(stream); + + /* + * write() is used behind the scenes of stdio output functions. + * Since git code does not check for errors after each stdio write + * operation, it can happen that write() is called by a later + * stdio function even if an earlier write() call failed. In the + * case of a pipe whose readable end was closed, only the first + * call to write() reports EPIPE on Windows. Subsequent write() + * calls report EINVAL. It is impossible to notice whether this + * fflush invocation triggered such a case, therefore, we have to + * catch all EINVAL errors whole-sale. + */ + if (ret && errno == EINVAL) + errno = EPIPE; + + return ret; +} + /* * The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC. * Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch. diff --git a/compat/mingw.h b/compat/mingw.h index 61a652138..eeb08d120 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -185,6 +185,9 @@ FILE *mingw_fopen (const char *filename, const char *otype); FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream); #define freopen mingw_freopen +int mingw_fflush(FILE *stream); +#define fflush mingw_fflush + char *mingw_getcwd(char *pointer, int len); #define getcwd mingw_getcwd |