path: root/src/stdio/fclose.c
diff options
authorRich Felker <>2015-06-16 07:11:19 +0000
committerRich Felker <>2015-06-16 07:11:19 +0000
commit1b0cdc8700d29ef018bf226d74b2b58b23bce91c (patch)
tree53c58824a9d73de47296b5a8885aefc9a1f39d0b /src/stdio/fclose.c
parentf22a9edaf8a6f2ca1d314d18b3785558279a5c03 (diff)
refactor stdio open file list handling, move it out of global libc struct
functions which open in-memory FILE stream variants all shared a tail with __fdopen, adding the FILE structure to stdio's open file list. replacing this common tail with a function call reduces code size and duplication of logic. the list is also partially encapsulated now. function signatures were chosen to facilitate tail call optimization and reduce the need for additional accessor functions. with these changes, static linked programs that do not use stdio no longer have an open file list at all.
Diffstat (limited to 'src/stdio/fclose.c')
1 files changed, 3 insertions, 3 deletions
diff --git a/src/stdio/fclose.c b/src/stdio/fclose.c
index 317b3c90..839d88af 100644
--- a/src/stdio/fclose.c
+++ b/src/stdio/fclose.c
@@ -14,11 +14,11 @@ int fclose(FILE *f)
if (!(perm = f->flags & F_PERM)) {
+ FILE **head = __ofl_lock();
if (f->prev) f->prev->next = f->next;
if (f->next) f->next->prev = f->prev;
- if (libc.ofl_head == f) libc.ofl_head = f->next;
+ if (*head == f) *head = f->next;
+ __ofl_unlock();
r = fflush(f);