From b5cd18739a64c8d923a55b61c89ae3900faafd84 Mon Sep 17 00:00:00 2001 From: Kacper Date: Tue, 9 Dec 2025 21:17:12 +0100 Subject: Fix include paths and formatting inconsistencies --- lib/libc/stdio/fdopen.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 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 23f94843..f762a83d 100644 --- a/lib/libc/stdio/fdopen.c +++ b/lib/libc/stdio/fdopen.c @@ -1,7 +1,12 @@ -#include -#include -#include -#include +#include "__stdio.h" // for __libc_fadd +#include "features.h" // for __weak +#include "stdatomic.h" // for atomic_flag_clear +#include "stddef.h" // for NULL + +#include // for __IMPL +#include // for FILE, _IONBF, SEEK_END, _IOLBF, fdopen +#include // for calloc, free +#include // for lseek, off_t __weak void __stdio_cleanup(void) { @@ -9,31 +14,32 @@ __weak void __stdio_cleanup(void) FILE *fdopen(int fildes, const char *mode) { - FILE *fp; + FILE *stream; if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a')) { return NULL; } - if ((fp = calloc(1, sizeof(FILE))) == NULL) + if ((stream = calloc(1, sizeof(FILE))) == NULL) return NULL; - fp->fd = fildes; - atomic_flag_clear(&fp->lock); + __IMPL(stream)->fd = fildes; + atomic_flag_clear(&__IMPL(stream)->lock); if (mode[0] == 'r') { - fp->type = _IONBF; + __IMPL(stream)->type = _IONBF; } else if (mode[0] == 'w') { - fp->type = _IOLBF; + __IMPL(stream)->type = _IOLBF; } else if (mode[0] == 'a') { - fp->type = _IONBF; + __IMPL(stream)->type = _IONBF; + off_t offset = lseek(fildes, 0, SEEK_END); if (offset == (off_t)-1) { - free(fp); + free(stream); return NULL; } } - __libc_fadd(fp); - return fp; + __libc_fadd(stream); + return stream; } -- cgit v1.2.3