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/fopen.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'lib/libc/stdio/fopen.c') diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c index 1f15820b..a56b907d 100644 --- a/lib/libc/stdio/fopen.c +++ b/lib/libc/stdio/fopen.c @@ -1,11 +1,15 @@ -#include -#include -#include -#include -#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 EINVAL, errno +#include // for O_WRONLY, O_CREAT, O_RDONLY, open, O_APPEND +#include // for __IMPL +#include // for FILE, BUFSIZ, fopen, _IOLBF +#include // for calloc, free, malloc +#include // for strchr +#include // for close __weak void __stdio_cleanup(void) { @@ -14,7 +18,7 @@ __weak void __stdio_cleanup(void) FILE *fopen(const char *restrict pathname, const char *restrict mode) { int fd, flags, _mode; - FILE *fp; + FILE *stream; _mode = 0; if (mode[0] == 'r') { @@ -36,21 +40,22 @@ FILE *fopen(const char *restrict pathname, const char *restrict mode) if ((fd = open(pathname, flags, _mode)) < 0) return NULL; - if ((fp = calloc(1, sizeof(FILE))) == NULL) + if ((stream = calloc(1, sizeof(FILE))) == NULL) return NULL; - fp->fd = fd; - fp->buf_size = BUFSIZ; - fp->flags = flags; - fp->type = _IOLBF; - atomic_flag_clear(&fp->lock); - if ((fp->buf = malloc(BUFSIZ)) == NULL) { + __IMPL(stream)->fd = fd; + __IMPL(stream)->buf_size = BUFSIZ; + __IMPL(stream)->flags = flags; + __IMPL(stream)->type = _IOLBF; + atomic_flag_clear(&stream->lock); + + if ((__IMPL(stream)->buf = malloc(BUFSIZ)) == NULL) { close(fd); - free(fp); + free(stream); return NULL; } - __libc_fadd(fp); + __libc_fadd(stream); - return fp; + return stream; } -- cgit v1.2.3