From 99d6c367c4820a072dc4ada51561df17e2093778 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Wed, 6 Dec 2006 22:41:21 +0000 Subject: stdio update from mjn3 --- libc/stdio/_fopen.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'libc/stdio/_fopen.c') diff --git a/libc/stdio/_fopen.c b/libc/stdio/_fopen.c index 02051eff9..5243e33f7 100644 --- a/libc/stdio/_fopen.c +++ b/libc/stdio/_fopen.c @@ -198,10 +198,23 @@ FILE attribute_hidden *_stdio_fopen(intptr_t fname_or_mode, #endif #ifdef __STDIO_HAS_OPENLIST - __STDIO_THREADLOCK_OPENLIST; - stream->__nextopen = _stdio_openlist; /* New files are inserted at */ - _stdio_openlist = stream; /* the head of the list. */ - __STDIO_THREADUNLOCK_OPENLIST; +#if defined(__UCLIBC_HAS_THREADS__) && defined(__STDIO_BUFFERS) + if (!(stream->__modeflags & __FLAG_FREEFILE)) + { + /* An freopen call so the file was never removed from the list. */ + } + else +#endif + { + /* We have to lock the del mutex in case another thread wants to fclose() + * the last file. */ + __STDIO_THREADLOCK_OPENLIST_DEL; + __STDIO_THREADLOCK_OPENLIST_ADD; + stream->__nextopen = _stdio_openlist; /* New files are inserted at */ + _stdio_openlist = stream; /* the head of the list. */ + __STDIO_THREADUNLOCK_OPENLIST_ADD; + __STDIO_THREADUNLOCK_OPENLIST_DEL; + } #endif __STDIO_STREAM_VALIDATE(stream); -- cgit v1.2.3