summaryrefslogtreecommitdiff
path: root/libc/stdio/_fopen.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2006-12-06 22:41:21 +0000
committerEric Andersen <andersen@codepoet.org>2006-12-06 22:41:21 +0000
commit99d6c367c4820a072dc4ada51561df17e2093778 (patch)
tree969945da0bce7248de98eefedaeb590f5cfdd85e /libc/stdio/_fopen.c
parentaeba32a371882d602f6863320880f0c69c824b77 (diff)
stdio update from mjn3
Diffstat (limited to 'libc/stdio/_fopen.c')
-rw-r--r--libc/stdio/_fopen.c21
1 files changed, 17 insertions, 4 deletions
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);