mirror of https://git.musl-libc.org/git/musl
Browse Source
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.master
12 changed files with 42 additions and 41 deletions
@ -0,0 +1,16 @@ |
|||
#include "stdio_impl.h" |
|||
#include "libc.h" |
|||
|
|||
static FILE *ofl_head; |
|||
static volatile int ofl_lock[2]; |
|||
|
|||
FILE **__ofl_lock() |
|||
{ |
|||
LOCK(ofl_lock); |
|||
return &ofl_head; |
|||
} |
|||
|
|||
void __ofl_unlock() |
|||
{ |
|||
UNLOCK(ofl_lock); |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
#include "stdio_impl.h" |
|||
|
|||
FILE *__ofl_add(FILE *f) |
|||
{ |
|||
FILE **head = __ofl_lock(); |
|||
f->next = *head; |
|||
if (*head) (*head)->prev = f; |
|||
*head = f; |
|||
__ofl_unlock(); |
|||
return f; |
|||
} |
|||
Loading…
Reference in new issue