diff options
Diffstat (limited to 'libc/stdio/fcloseall.c')
-rw-r--r-- | libc/stdio/fcloseall.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/libc/stdio/fcloseall.c b/libc/stdio/fcloseall.c index 7d2422562..d3cbb67f8 100644 --- a/libc/stdio/fcloseall.c +++ b/libc/stdio/fcloseall.c @@ -24,14 +24,39 @@ int fcloseall (void) #ifdef __STDIO_HAS_OPENLIST int retval = 0; + FILE *f; - __STDIO_THREADLOCK_OPENLIST; - while (_stdio_openlist) { - if (fclose(_stdio_openlist)) { - retval = EOF; + __STDIO_OPENLIST_INC_USE; + +#ifdef __UCLIBC_MJN3_ONLY__ +#warning REMINDER: should probably have a get_head() operation +#endif + __STDIO_THREADLOCK_OPENLIST_ADD; + f = _stdio_openlist; + __STDIO_THREADUNLOCK_OPENLIST_ADD; + + while (f) { +#ifdef __UCLIBC_MJN3_ONLY__ +#warning REMINDER: should probably have a get_next() operation +#endif + FILE *n = f->__nextopen; + __STDIO_AUTO_THREADLOCK_VAR; + + __STDIO_AUTO_THREADLOCK(f); + /* Only call fclose on the stream if it is not already closed. */ + if ((f->__modeflags & (__FLAG_READONLY|__FLAG_WRITEONLY)) + != (__FLAG_READONLY|__FLAG_WRITEONLY) + ) { + if (fclose(f)) { + retval = EOF; + } } + __STDIO_AUTO_THREADUNLOCK(f); + + f = n; } - __STDIO_THREADUNLOCK_OPENLIST; + + __STDIO_OPENLIST_DEC_USE; return retval; |