changeset 8721:5122cdde0f7b

Fix fflush on mingw. * modules/fflush (Depends-on): Add freading. * lib/fflush.c (rpl_fflush): Use freading to avoid losing buffered but unread data.
author Eric Blake <ebb9@byu.net>
date Thu, 26 Apr 2007 13:20:50 +0000
parents 367787d55c9c
children 8f16230a2a6a
files ChangeLog lib/fflush.c modules/fflush
diffstat 3 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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>
 
--- 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 @@
   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.  */
--- a/modules/fflush
+++ b/modules/fflush
@@ -10,6 +10,7 @@
 Depends-on:
 fpurge
 ftello
+freading
 stdio
 unistd