summaryrefslogtreecommitdiff
path: root/libc/stdio/fcloseall.c
blob: 7d24225629dc74628945ac59a92cace4bce42dc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
 *
 * GNU Library General Public License (LGPL) version 2 or later.
 *
 * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
 */

#include <features.h>

#ifdef __USE_GNU
#include "_stdio.h"

libc_hidden_proto(fclose)

/* NOTE: GLIBC difference!!! -- fcloseall
 * According to the info pages, glibc actually fclose()s all open files.
 * Apparently, glibc's new version only fflush()s and unbuffers all
 * writing streams to cope with unordered destruction of c++ static
 * objects.
 */

int fcloseall (void)
{
#ifdef __STDIO_HAS_OPENLIST

	int retval = 0;

	__STDIO_THREADLOCK_OPENLIST;
	while (_stdio_openlist) {
		if (fclose(_stdio_openlist)) {
			retval = EOF;
		}
	}
	__STDIO_THREADUNLOCK_OPENLIST;

	return retval;

#else

#warning Always fails in this configuration because no open file list.

	return EOF;

#endif
}
#endif