[uClibc-cvs] uClibc/libc/stdio stdio.c,1.67,1.68
Manuel Novoa III
mjn3 at uclibc.org
Tue Jun 24 04:07:44 UTC 2003
Update of /var/cvs/uClibc/libc/stdio
In directory winder:/tmp/cvs-serv20440
Modified Files:
stdio.c
Log Message:
Change 'undefined behavior' of fflush() on readonly or reading streams
to match that of current glibc; i.e. don't do anything and return success.
Apparently, php calls fflush() on a file opened as readonly before trying
to read. Eventually I'll add some config options to flag this and several
other instances of nonportable code.
Index: stdio.c
===================================================================
RCS file: /var/cvs/uClibc/libc/stdio/stdio.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- stdio.c 15 May 2003 21:32:31 -0000 1.67
+++ stdio.c 24 Jun 2003 04:07:40 -0000 1.68
@@ -2210,14 +2210,18 @@
if (_stdio_fwrite(NULL, 0, stream) > 0) { /* flush buffer contents. */
rv = -1; /* Not all chars written. */
}
- } else if (stream->modeflags & __FLAG_READONLY) {
- /* According to info, glibc returns an error when the file is opened
- * in read-only mode.
- * ANSI/ISO says behavior in this case is undefined but also says you
- * shouldn't flush a stream you were reading from. */
- stream->modeflags |= __FLAG_ERROR; /* TODO - check glibc behavior */
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning add option to test for undefined behavior of fflush
+#endif /* __UCLIBC_MJN3_ONLY__ */
+#if 0
+ } else if (stream->modeflags & (__FLAG_READING|__FLAG_READONLY)) {
+ /* ANSI/ISO says behavior in this case is undefined but also says you
+ * shouldn't flush a stream you were reading from. As usual, glibc
+ * caters to broken programs and simply ignores this. */
+ stream->modeflags |= __FLAG_ERROR;
__set_errno(EBADF);
rv = -1;
+#endif
}
#ifndef NDEBUG
@@ -2235,11 +2239,17 @@
}
#endif
- /* TODO -- check glibc behavior regarding error indicator */
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning add option to test for undefined behavior of fflush
+#endif /* __UCLIBC_MJN3_ONLY__ */
+#if 0
return ((stream != NULL)
- && (stream->modeflags & __FLAG_READONLY)
+ && (stream->modeflags & (__FLAG_READING|__FLAG_READONLY))
? ((stream->modeflags |= __FLAG_ERROR), __set_errno(EBADF), EOF)
: 0 );
+#else
+ return 0;
+#endif
#endif /* __STDIO_BUFFERS */
}
More information about the uClibc-cvs
mailing list