summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/fdopen.c
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-09 21:17:12 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-09 21:17:12 +0100
commitb5cd18739a64c8d923a55b61c89ae3900faafd84 (patch)
treed192f7b25257ae9a8a4760c68f5314dcbc0d9b91 /lib/libc/stdio/fdopen.c
parent119aed5bc787ccbf23d2f151759ec1f3a80977e1 (diff)
Fix include paths and formatting inconsistencies
Diffstat (limited to 'lib/libc/stdio/fdopen.c')
-rw-r--r--lib/libc/stdio/fdopen.c34
1 files changed, 20 insertions, 14 deletions
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 <io.h>
-#include <libc.h>
-#include <unistd.h>
-#include <stdio.h>
+#include "__stdio.h" // for __libc_fadd
+#include "features.h" // for __weak
+#include "stdatomic.h" // for atomic_flag_clear
+#include "stddef.h" // for NULL
+
+#include <libc.h> // for __IMPL
+#include <stdio.h> // for FILE, _IONBF, SEEK_END, _IOLBF, fdopen
+#include <stdlib.h> // for calloc, free
+#include <unistd.h> // 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;
}