diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2003-06-24 04:07:40 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2003-06-24 04:07:40 +0000 |
commit | dba553769ed6437444b635ba8818e5a3cb252e00 (patch) | |
tree | 93136566ff450008e56169a195babcefdc90bd1d /libc/stdio/stdio.c | |
parent | efe2271a53aee5145308349d31e6d45a8571758a (diff) |
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.
Diffstat (limited to 'libc/stdio/stdio.c')
-rw-r--r-- | libc/stdio/stdio.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/libc/stdio/stdio.c b/libc/stdio/stdio.c index eec8bdda3..9a7afbc85 100644 --- a/libc/stdio/stdio.c +++ b/libc/stdio/stdio.c @@ -2210,14 +2210,18 @@ int fflush_unlocked(register FILE *stream) 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 @@ int fflush_unlocked(register FILE *stream) } #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 */ } |