From 69e6fe89fa9baafeca3e3515bb50897cd8ee7c35 Mon Sep 17 00:00:00 2001 From: Kacper Date: Mon, 15 Dec 2025 18:24:54 +0100 Subject: Add getauxval and cleanup libc startup --- lib/libc/stdio/fdopen.c | 14 +++++--------- lib/libc/stdio/fmemopen.c | 7 ++++--- lib/libc/stdio/fopen.c | 16 +++++++++------- lib/libc/stdio/stdin.c | 8 ++++---- lib/libc/stdio/stdout.c | 5 ++--- 5 files changed, 24 insertions(+), 26 deletions(-) (limited to 'lib/libc/stdio') diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c index c5db3854..bded5f27 100644 --- a/lib/libc/stdio/fdopen.c +++ b/lib/libc/stdio/fdopen.c @@ -1,10 +1,7 @@ -#include "__stdio.h" // for __FILE, __libc_fadd -#include "features.h" // for __weak -#include "stdatomic.h" // for atomic_flag_clear -#include "stddef.h" // for NULL - -#include // for FILE, _IONBF, SEEK_END, _IOLBF, fdopen -#include // for calloc, free +#include "__stdio.h" // for __FILE, __libc_fadd +#include // for FILE, _IONBF, SEEK_END, _IOLBF, fdopen +#include // for calloc, free +#include #include // for lseek, off_t __weak void __stdio_cleanup(void) @@ -15,8 +12,7 @@ FILE *fdopen(int fildes, const char *mode) { FILE *stream; - if (mode == NULL || - (mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a')) { + if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a')) { return NULL; } diff --git a/lib/libc/stdio/fmemopen.c b/lib/libc/stdio/fmemopen.c index 920484b3..e1b2ccff 100644 --- a/lib/libc/stdio/fmemopen.c +++ b/lib/libc/stdio/fmemopen.c @@ -1,6 +1,5 @@ -#include "__stdio.h" // for __FILE, __libc_fadd -#include "features.h" // for __weak -#include "stddef.h" // for NULL +#include "__stdio.h" // for __FILE, __libc_fadd +#include "stddef.h" // for NULL #include // for EINVAL, errno #include // for O_WRONLY, O_CREAT, O_RDONLY, O_APPEND, O_RDWR @@ -8,6 +7,8 @@ #include // for calloc, free #include // for strchr +#include + __weak void __stdio_cleanup(void) { } diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c index bef21f46..5415e711 100644 --- a/lib/libc/stdio/fopen.c +++ b/lib/libc/stdio/fopen.c @@ -1,13 +1,11 @@ -#include "__stdio.h" // for __FILE, __libc_fadd -#include "features.h" // for __weak -#include "stdatomic.h" // for atomic_flag_clear -#include "stddef.h" // for NULL +#include <__stdio.h> #include // for EINVAL, errno #include // for O_WRONLY, O_CREAT, O_RDONLY, open, O_APPEND #include // for FILE, BUFSIZ, fopen, _IOLBF #include // for calloc, free, malloc #include // for strchr +#include #include // for close __weak void __stdio_cleanup(void) @@ -36,10 +34,12 @@ FILE *fopen(const char *restrict pathname, const char *restrict mode) flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR; } - if ((fd = open(pathname, flags, _mode)) < 0) + fd = open(pathname, flags, _mode); + if (fd < 0) return NULL; - if ((stream = calloc(1, sizeof(FILE))) == NULL) + stream = calloc(1, sizeof(struct __FILE)); + if (stream == NULL) return NULL; __FILE(stream)->fd = fd; @@ -48,7 +48,9 @@ FILE *fopen(const char *restrict pathname, const char *restrict mode) __FILE(stream)->type = _IOLBF; atomic_flag_clear(&__FILE(stream)->lock); - if ((__FILE(stream)->buf = malloc(BUFSIZ)) == NULL) { + __FILE(stream)->buf = malloc(BUFSIZ); + + if (__FILE(stream)->buf == NULL) { close(fd); free(stream); return NULL; diff --git a/lib/libc/stdio/stdin.c b/lib/libc/stdio/stdin.c index 45d42e27..0d127efa 100644 --- a/lib/libc/stdio/stdin.c +++ b/lib/libc/stdio/stdin.c @@ -1,8 +1,8 @@ -#include "__stdio.h" // for __FILE -#include "features.h" // for __weak +#include "__stdio.h" // for __FILE -#include // for O_RDONLY -#include // for FILE, stdin +#include // for O_RDONLY +#include // for FILE, stdin +#include #include // for STDOUT_FILENO #define BUFSIZ 4096 diff --git a/lib/libc/stdio/stdout.c b/lib/libc/stdio/stdout.c index 14637368..471a54b9 100644 --- a/lib/libc/stdio/stdout.c +++ b/lib/libc/stdio/stdout.c @@ -1,11 +1,10 @@ -#include "__stdio.h" // for __FILE, __libc_fadd -#include "features.h" // for __weak -#include "stdatomic.h" // for ATOMIC_FLAG_INIT, atomic_flag +#include "__stdio.h" // for __FILE, __libc_fadd #include // for LIBC_LOCK, LIBC_UNLOCK #include // for O_WRONLY #include // for NULL #include // for stdout +#include #include // for STDOUT_FILENO #define BUFSIZ 4096 -- cgit v1.2.3