373a2c76cc5b71b872817bf4735c7369a6bc4f82
[musl] / src / stdio / fclose.c
1 #include "stdio_impl.h"
2
3 int fclose(FILE *f)
4 {
5         int r;
6         int perm = f->flags & F_PERM;
7
8         if (!perm) {
9                 OFLLOCK();
10                 if (f->prev) f->prev->next = f->next;
11                 if (f->next) f->next->prev = f->prev;
12                 if (libc.ofl_head == f) libc.ofl_head = f->next;
13                 OFLUNLOCK();
14         }
15
16         r = fflush(f);
17         r |= f->close(f);
18
19         if (!perm) free(f);
20         
21         return r;
22 }