summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/fopen.c
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-15 18:24:54 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-15 18:24:54 +0100
commit69e6fe89fa9baafeca3e3515bb50897cd8ee7c35 (patch)
tree489046ce167b8b20d205f87f4ae1f4b680c19b43 /lib/libc/stdio/fopen.c
parent0d5bffe9d2caadc1215c875e560c52bca5161c54 (diff)
Add getauxval and cleanup libc startup
Diffstat (limited to 'lib/libc/stdio/fopen.c')
-rw-r--r--lib/libc/stdio/fopen.c16
1 files changed, 9 insertions, 7 deletions
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 <errno.h> // for EINVAL, errno
#include <fcntl.h> // for O_WRONLY, O_CREAT, O_RDONLY, open, O_APPEND
#include <stdio.h> // for FILE, BUFSIZ, fopen, _IOLBF
#include <stdlib.h> // for calloc, free, malloc
#include <string.h> // for strchr
+#include <sys/cdefs.h>
#include <unistd.h> // 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;