initial check-in, version 0.5.0
[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 (ofl_head == f) ofl_head = f->next;
13                 OFLUNLOCK();
14         }
15
16         r = fflush(f) | f->close(f);
17
18         if (!perm) free(f);
19         
20         return r;
21 }