Fix fflush on mingw.
authorEric Blake <ebb9@byu.net>
Thu, 26 Apr 2007 13:20:50 +0000 (13:20 +0000)
committerEric Blake <ebb9@byu.net>
Thu, 26 Apr 2007 13:20:50 +0000 (13:20 +0000)
* modules/fflush (Depends-on): Add freading.
* lib/fflush.c (rpl_fflush): Use freading to avoid losing buffered
but unread data.

ChangeLog
lib/fflush.c
modules/fflush

index 6d6d954db6b51390cef47874526b1961cfb036bf..f26e6b7ee1dc1f57f31c55e8d125e36816a394ab 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-04-26  Eric Blake  <ebb9@byu.net>
+
+       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  <ebb9@byu.net>
        and Bruno Haible  <bruno@clisp.org>
 
index aae6ac67a39fa746f67a8084b6fde675aa36ccfd..9361c09f3fa15d5855aa9caf366168e14a53679c 100755 (executable)
@@ -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.  */
index 8cfc04661c85457e0dd948ecc8e8272ef9f7b5e1..9caf403ab0230b10108b3fc718dc5f2b1556362b 100755 (executable)
@@ -10,6 +10,7 @@ m4/fseeko.m4
 Depends-on:
 fpurge
 ftello
+freading
 stdio
 unistd