bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'fflush' test failure on Cygwin


From: Eric Blake
Subject: Re: 'fflush' test failure on Cygwin
Date: Thu, 26 Apr 2007 07:14:54 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.10) Gecko/20070221 Thunderbird/1.5.0.10 Mnenhy/0.7.5.666

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  <address@hidden>

        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             address@hidden
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
 

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]