summaryrefslogtreecommitdiff
path: root/src/stdio/__stdio_exit.c
blob: 716e5f7366095455791db3616f6f63168298ba27 (plain) (blame)
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
#include "stdio_impl.h"

static FILE *volatile dummy_file = 0;
weak_alias(dummy_file, __stdin_used);
weak_alias(dummy_file, __stdout_used);
weak_alias(dummy_file, __stderr_used);

static void close_file(FILE *f)
{
	if (!f) return;
	FFINALLOCK(f);
	if (f->wpos > f->wbase) f->write(f, 0, 0);
	if (f->rpos < f->rend) f->seek(f, f->rpos-f->rend, SEEK_CUR);
}

void __stdio_exit(void)
{
	FILE *f;
	OFLLOCK();
	for (f=libc.ofl_head; f; f=f->next) close_file(f);
	close_file(__stdin_used);
	close_file(__stdout_used);
}

weak_alias(__stdio_exit, __stdio_exit_needed);