netinet/in.h: add IPPROTO_MH
[uclibc-ng.git] / libc / stdio / fcloseall.c
blobab8248c7be0ad27aeff7eb2b814438af6c646324
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 __STDIO_THREADLOCK_OPENLIST_ADD;
31 f = _stdio_openlist;
32 __STDIO_THREADUNLOCK_OPENLIST_ADD;
34 while (f) {
35 FILE *n = f->__nextopen;
36 __STDIO_AUTO_THREADLOCK_VAR;
38 __STDIO_AUTO_THREADLOCK(f);
39 /* Only call fclose on the stream if it is not already closed. */
40 if ((f->__modeflags & (__FLAG_READONLY|__FLAG_WRITEONLY))
41 != (__FLAG_READONLY|__FLAG_WRITEONLY)
42 ) {
43 if (fclose(f)) {
44 retval = EOF;
47 __STDIO_AUTO_THREADUNLOCK(f);
49 f = n;
52 __STDIO_OPENLIST_DEC_USE;
54 return retval;
56 #else
58 #warning Always fails in this configuration because no open file list.
60 return EOF;
62 #endif
64 #endif