libc: fix MIPS N64 fork
[uclibc-ng.git] / libc / stdio / fcloseall.c
blob4d78b37d64019b5691bc7763c37f632c8e49ceda
1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
6 */
8 #include <features.h>
10 #ifdef __USE_GNU
11 #include "_stdio.h"
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.
21 int fcloseall (void)
23 #ifdef __STDIO_HAS_OPENLIST
25 int retval = 0;
26 FILE *f;
28 __STDIO_OPENLIST_INC_USE;
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;
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;
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;
53 __STDIO_AUTO_THREADUNLOCK(f);
55 f = n;
58 __STDIO_OPENLIST_DEC_USE;
60 return retval;
62 #else
64 #warning Always fails in this configuration because no open file list.
66 return EOF;
68 #endif
70 #endif