diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-22 23:27:56 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-22 23:30:32 +0100 |
| commit | 0f30d227497418c6d3bef7d52244407e30454504 (patch) | |
| tree | 0e1ac19623d3268380cf74328cdf643648a2f43c /lib/libc/stdio/fdopen.c | |
| parent | 90dad97fc07f049383903a166631e2c257f9b8c1 (diff) | |
Added c11 threads, fixed some locks and add *_unlocked functions
Diffstat (limited to 'lib/libc/stdio/fdopen.c')
| -rw-r--r-- | lib/libc/stdio/fdopen.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c index bded5f27..dc9da567 100644 --- a/lib/libc/stdio/fdopen.c +++ b/lib/libc/stdio/fdopen.c @@ -4,33 +4,30 @@ #include <sys/cdefs.h> #include <unistd.h> // for lseek, off_t -__weak void __stdio_cleanup(void) -{ -} - FILE *fdopen(int fildes, const char *mode) { - FILE *stream; + struct __FILE *stream; if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a')) { return NULL; } - stream = calloc(1, sizeof(FILE)); + stream = calloc(1, sizeof(struct __FILE)); if (stream == NULL) return NULL; - __FILE(stream)->fd = fildes; - atomic_flag_clear(&__FILE(stream)->lock); + stream->fd = fildes; + atomic_flag_clear(&stream->lock); + if (mode[0] == 'r') { - __FILE(stream)->type = _IONBF; + stream->type = _IONBF; } else if (mode[0] == 'w') { - __FILE(stream)->type = _IOLBF; + stream->type = _IOLBF; } else if (mode[0] == 'a') { - __FILE(stream)->type = _IONBF; - - off_t offset = lseek(fildes, 0, SEEK_END); - if (offset == (off_t)-1) { + off_t off; + stream->type = _IONBF; + off = lseek(fildes, 0, SEEK_END); + if (off == (off_t)-1) { free(stream); return NULL; } |
