+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>
#include <errno.h>
#include <unistd.h>
+#include "freading.h"
#include "fpurge.h"
#undef fflush
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. */