1#include "stdio_impl.h"
2
3static void close_file(FILE* f) {
4    if (!f)
5        return;
6    FFINALLOCK(f);
7    if (f->wpos > f->wbase)
8        f->write(f, 0, 0);
9    if (f->rpos < f->rend)
10        f->seek(f, f->rpos - f->rend, SEEK_CUR);
11}
12
13void __stdio_exit(void) {
14    FILE* f;
15    for (f = *__ofl_lock(); f; f = f->next)
16        close_file(f);
17    close_file(stdin);
18    close_file(stdout);
19}
20