From: Eric Blake Date: Thu, 26 Apr 2007 13:20:50 +0000 (+0000) Subject: Fix fflush on mingw. X-Git-Tag: cvs-readonly~497 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=9b87488be4a30247c1eabd71408e1e953b797c22;p=gnulib.git Fix fflush on mingw. * modules/fflush (Depends-on): Add freading. * lib/fflush.c (rpl_fflush): Use freading to avoid losing buffered but unread data. --- diff --git a/ChangeLog b/ChangeLog index 6d6d954db..f26e6b7ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,11 @@ 2007-04-26 Eric Blake + + Fix fflush on mingw. + * modules/fflush (Depends-on): Add freading. + * lib/fflush.c (rpl_fflush): Use freading to avoid losing buffered + but unread data. + +2007-04-26 Eric Blake and Bruno Haible Implement freading and fwriting. diff --git a/lib/fflush.c b/lib/fflush.c index aae6ac67a..9361c09f3 100755 --- a/lib/fflush.c +++ b/lib/fflush.c @@ -25,6 +25,7 @@ #include #include +#include "freading.h" #include "fpurge.h" #undef fflush @@ -37,13 +38,12 @@ rpl_fflush (FILE *stream) int result; off_t pos; - /* Try flushing the stream. C89 guarantees behavior of output - streams, so we only need to worry if failure might have been on - an input stream. When stream is NULL, POSIX only requires - flushing of output streams. */ - result = fflush (stream); - if (! stream || result == 0 || errno != EBADF) - return result; + /* When stream is NULL, POSIX only requires flushing of output + streams. C89 guarantees behavior of output streams, and fflush + should be safe on read-write streams that are not currently + reading. */ + if (! stream || ! freading (stream)) + return fflush (stream); /* POSIX does not specify fflush behavior for non-seekable input streams. */ diff --git a/modules/fflush b/modules/fflush index 8cfc04661..9caf403ab 100755 --- a/modules/fflush +++ b/modules/fflush @@ -10,6 +10,7 @@ m4/fseeko.m4 Depends-on: fpurge ftello +freading stdio unistd