summaryrefslogtreecommitdiff
path: root/libc/stdio/stdio.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2002-03-12 17:03:43 +0000
committerManuel Novoa III <mjn3@codepoet.org>2002-03-12 17:03:43 +0000
commit0343687b86ed007d78615d2da191ec341aed1c4c (patch)
tree99a72f9aba77b6bf4f9dee2583f48508ac330748 /libc/stdio/stdio.c
parent4b1902f742cd468586b8e27dea46fd054839b5c6 (diff)
Fix fflush(NULL) and tweak _stdio_term() for the unbuffered stdio option.
Diffstat (limited to 'libc/stdio/stdio.c')
-rw-r--r--libc/stdio/stdio.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/libc/stdio/stdio.c b/libc/stdio/stdio.c
index 01e0e35e9..8c2e7afdc 100644
--- a/libc/stdio/stdio.c
+++ b/libc/stdio/stdio.c
@@ -1723,10 +1723,12 @@ void _stdio_term(void)
}
#endif /* __STDIO_THREADSAFE */
+#ifdef __STDIO_BUFFERS
/* TODO -- set an alarm and flush each file "by hand"? to avoid blocking? */
/* Now flush all streams. */
fflush(NULL);
+#endif /* __STDIO_BUFFERS */
/* Next close all custom streams in case of any special cleanup, but
* don't use fclose() because that pulls in free and malloc. Also,
@@ -2031,9 +2033,15 @@ int fflush_unlocked(register FILE *stream)
#else /* __STDIO_BUFFERS --------------------------------------- */
- __stdio_validate_FILE(stream); /* debugging only */
+#ifndef NDEBUG
+ if ((stream != NULL) && (stream != (FILE *) &_stdio_openlist)) {
+ __stdio_validate_FILE(stream); /* debugging only */
+ }
+#endif
+
/* TODO -- check glibc behavior regarding error indicator */
- return (stream->modeflags & (__FLAG_READONLY|__FLAG_READING)
+ return ((stream != NULL)
+ && (stream->modeflags & (__FLAG_READONLY|__FLAG_READING))
? ((stream->modeflags |= __FLAG_ERROR), __set_errno(EBADF), EOF)
: 0 );