lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org> |
| 2 | * |
| 3 | * GNU Library General Public License (LGPL) version 2 or later. |
| 4 | * |
| 5 | * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details. |
| 6 | */ |
| 7 | |
| 8 | #include <features.h> |
| 9 | |
| 10 | #ifdef __USE_GNU |
| 11 | #include "_stdio.h" |
| 12 | |
| 13 | |
| 14 | /* NOTE: GLIBC difference!!! -- fcloseall |
| 15 | * According to the info pages, glibc actually fclose()s all open files. |
| 16 | * Apparently, glibc's new version only fflush()s and unbuffers all |
| 17 | * writing streams to cope with unordered destruction of c++ static |
| 18 | * objects. |
| 19 | */ |
| 20 | |
| 21 | int fcloseall (void) |
| 22 | { |
| 23 | #ifdef __STDIO_HAS_OPENLIST |
| 24 | |
| 25 | int retval = 0; |
| 26 | FILE *f; |
| 27 | |
| 28 | __STDIO_OPENLIST_INC_USE; |
| 29 | |
| 30 | #ifdef __UCLIBC_MJN3_ONLY__ |
| 31 | #warning REMINDER: should probably have a get_head() operation |
| 32 | #endif |
| 33 | __STDIO_THREADLOCK_OPENLIST_ADD; |
| 34 | f = _stdio_openlist; |
| 35 | __STDIO_THREADUNLOCK_OPENLIST_ADD; |
| 36 | |
| 37 | while (f) { |
| 38 | #ifdef __UCLIBC_MJN3_ONLY__ |
| 39 | #warning REMINDER: should probably have a get_next() operation |
| 40 | #endif |
| 41 | FILE *n = f->__nextopen; |
| 42 | __STDIO_AUTO_THREADLOCK_VAR; |
| 43 | |
| 44 | __STDIO_AUTO_THREADLOCK(f); |
| 45 | /* Only call fclose on the stream if it is not already closed. */ |
| 46 | if ((f->__modeflags & (__FLAG_READONLY|__FLAG_WRITEONLY)) |
| 47 | != (__FLAG_READONLY|__FLAG_WRITEONLY) |
| 48 | ) { |
| 49 | if (fclose(f)) { |
| 50 | retval = EOF; |
| 51 | } |
| 52 | } |
| 53 | __STDIO_AUTO_THREADUNLOCK(f); |
| 54 | |
| 55 | f = n; |
| 56 | } |
| 57 | |
| 58 | __STDIO_OPENLIST_DEC_USE; |
| 59 | |
| 60 | return retval; |
| 61 | |
| 62 | #else |
| 63 | |
| 64 | #warning Always fails in this configuration because no open file list. |
| 65 | |
| 66 | return EOF; |
| 67 | |
| 68 | #endif |
| 69 | } |
| 70 | #endif |