From: Eric Blake Date: Thu, 26 Apr 2007 13:20:50 +0000 (+0000) Subject: Fix fflush on mingw. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b87488be4a30247c1eabd71408e1e953b797c22;p=pspp 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 6d6d954db6..f26e6b7ee1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +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 diff --git a/lib/fflush.c b/lib/fflush.c index aae6ac67a3..9361c09f3f 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 8cfc04661c..9caf403ab0 100755 --- a/modules/fflush +++ b/modules/fflush @@ -10,6 +10,7 @@ m4/fseeko.m4 Depends-on: fpurge ftello +freading stdio unistd