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

[MiNT] fflush patch for mintlib



In mintlib CVS we check for a write operation on the FILE stream for
fflush().

The problem is that some programs try to do a fflush() operation on a
read-only file, and the information I've found is that operation is
undefined, but certainly on Linux (and I think there's patches for
FreeBSD if they haven't made it already) to return no error when trying
to fflush() on a read only file.

The patch below does that.

It also removes a duplicate check which __flshfp() does anyway.

Frank - any problems with this ?

Alan.
Index: stdio/fflush.c
===================================================================
RCS file: /mint/mintlib/stdio/fflush.c,v
retrieving revision 1.2
diff -u -r1.2 fflush.c
--- stdio/fflush.c	19 Jul 2001 21:01:01 -0000	1.2
+++ stdio/fflush.c	14 Dec 2007 10:08:12 -0000
@@ -26,6 +26,11 @@
 fflush (stream)
      register FILE *stream;
 {
+  if (stream->__mode.__read && !stream->__mode.__write)
+    {
+      return 0; /* no error on read only file */
+    }
+
   if (stream == NULL)
     {
       int lossage = 0;
@@ -35,12 +40,6 @@
       return lossage ? EOF : 0;
     }
 
-  if (!__validfp (stream) || !stream->__mode.__write)
-    {
-      __set_errno (EINVAL);
-      return EOF;
-    }
-
   return __flshfp (stream, EOF);
 }
 weak_alias(fflush, fflush_unlocked)