From 0f30d227497418c6d3bef7d52244407e30454504 Mon Sep 17 00:00:00 2001 From: Kacper Date: Mon, 22 Dec 2025 23:27:56 +0100 Subject: Added c11 threads, fixed some locks and add *_unlocked functions --- lib/libc/stdio/fdopen.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'lib/libc/stdio/fdopen.c') 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 #include // 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; } -- cgit v1.2.3