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/fopen.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/libc/stdio/fopen.c') 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; -- cgit v1.2.3