From 0343687b86ed007d78615d2da191ec341aed1c4c Mon Sep 17 00:00:00 2001 From: Manuel Novoa III Date: Tue, 12 Mar 2002 17:03:43 +0000 Subject: Fix fflush(NULL) and tweak _stdio_term() for the unbuffered stdio option. --- libc/stdio/stdio.c | 12 ++++++++++-- 1 file 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 ); -- cgit v1.2.3