blob: a5e42c675fa90c4edc2ebde2576aaa543ed91a14 [file] [log] [blame]
Andrew Top286dd782018-10-02 16:52:45 -07001#include "stdio_impl.h"
2
3static FILE *volatile dummy_file = 0;
4weak_alias(dummy_file, __stdin_used);
5weak_alias(dummy_file, __stdout_used);
6weak_alias(dummy_file, __stderr_used);
7
8static void close_file(FILE *f)
9{
10 if (!f) return;
11 FFINALLOCK(f);
Kaido Kert788710a2023-06-05 07:50:22 -070012 if (f->wpos != f->wbase) f->write(f, 0, 0);
13 if (f->rpos != f->rend) f->seek(f, f->rpos-f->rend, SEEK_CUR);
Andrew Top286dd782018-10-02 16:52:45 -070014}
15
16void __stdio_exit(void)
17{
18 FILE *f;
19 for (f=*__ofl_lock(); f; f=f->next) close_file(f);
20 close_file(__stdin_used);
21 close_file(__stdout_used);
22 close_file(__stderr_used);
23}
24
25weak_alias(__stdio_exit, __stdio_exit_needed);