source:
EcnlProtoTool/trunk/musl-1.1.18/src/stdio/fclose.c
Last change on this file was 444, checked in by , 4 years ago | |
---|---|
|
|
File size: 600 bytes |
Line | |
---|---|
1 | #include "stdio_impl.h" |
2 | #include "libc.h" |
3 | |
4 | #ifndef __c2__ |
5 | static void dummy(FILE *f) { } |
6 | weak_alias(dummy, __unlist_locked_file); |
7 | #else |
8 | extern void __unlist_locked_file(FILE *f); |
9 | #endif |
10 | |
11 | int fclose(FILE *f) |
12 | { |
13 | int r; |
14 | int perm; |
15 | |
16 | FLOCK(f); |
17 | |
18 | __unlist_locked_file(f); |
19 | |
20 | if (!(perm = f->flags & F_PERM)) { |
21 | FILE **head = __ofl_lock(); |
22 | if (f->prev) f->prev->next = f->next; |
23 | if (f->next) f->next->prev = f->prev; |
24 | if (*head == f) *head = f->next; |
25 | __ofl_unlock(); |
26 | } |
27 | |
28 | r = fflush(f); |
29 | r |= f->close(f); |
30 | |
31 | if (f->getln_buf) free(f->getln_buf); |
32 | if (!perm) free(f); |
33 | else FUNLOCK(f); |
34 | |
35 | return r; |
36 | } |
Note:
See TracBrowser
for help on using the repository browser.