According to Eric Blake on 4/25/2007 7:22 AM: > Thanks. The next problem is figuring out how to work around the fact that > on mingw, fflush(stdin) returns 0 and moves the file offset to the end of > the buffer, rather than failing with EBADF, unlike all the other platforms > where fflush(stdin) is broken but at least leaves stdin alone.
Like so: 2007-04-26 Eric Blake <[EMAIL PROTECTED]> Fix fflush on mingw. * modules/fflush (Depends-on): Add freading. * lib/fflush.c (rpl_fflush): Use freading to avoid losing buffered but unread data. -- Don't work too hard, make some time for fun as well! Eric Blake [EMAIL PROTECTED]
diff --git a/lib/fflush.c b/lib/fflush.c index 7481e66..c58bfb9 100644 --- a/lib/fflush.c +++ b/lib/fflush.c @@ -25,6 +25,7 @@ #include <errno.h> #include <unistd.h> +#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 62a2d59..ed2872a 100644 --- a/modules/fflush +++ b/modules/fflush @@ -10,6 +10,7 @@ m4/fseeko.m4 Depends-on: fpurge ftello +freading stdio unistd
signature.asc
Description: OpenPGP digital signature