summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/fmemopen.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/fmemopen.c
parent119aed5bc787ccbf23d2f151759ec1f3a80977e1 (diff)
Fix include paths and formatting inconsistencies
Diffstat (limited to 'lib/libc/stdio/fmemopen.c')
-rw-r--r--lib/libc/stdio/fmemopen.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/libc/stdio/fmemopen.c b/lib/libc/stdio/fmemopen.c
index b1fa0f8a..21e811fd 100644
--- a/lib/libc/stdio/fmemopen.c
+++ b/lib/libc/stdio/fmemopen.c
@@ -1,10 +1,13 @@
-#include <io.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <libc.h>
+#include "__stdio.h" // for __libc_fadd
+#include "features.h" // for __weak
+#include "stddef.h" // for NULL
+
+#include <errno.h> // for EINVAL, errno
+#include <fcntl.h> // for O_WRONLY, O_CREAT, O_RDONLY, O_APPEND, O_RDWR
+#include <libc.h> // for __IMPL
+#include <stdio.h> // for FILE, _IOFBF, fmemopen, size_t
+#include <stdlib.h> // for calloc, free
+#include <string.h> // for strchr
__weak void __stdio_cleanup(void)
{
@@ -13,15 +16,15 @@ __weak void __stdio_cleanup(void)
FILE *fmemopen(void *restrict buf, size_t max_size, const char *restrict mode)
{
int flags;
- FILE *f = calloc(1, sizeof(FILE));
+ FILE *stream = calloc(1, sizeof(FILE));
- if (f == NULL)
- return f;
+ if (stream == NULL)
+ return stream;
- f->fd = -1;
- f->buf = buf;
- f->buf_size = max_size;
- f->type = _IOFBF;
+ __IMPL(stream)->fd = -1;
+ __IMPL(stream)->buf = buf;
+ __IMPL(stream)->buf_size = max_size;
+ __IMPL(stream)->type = _IOFBF;
if (mode[0] == 'r') {
flags = O_RDONLY;
@@ -30,7 +33,7 @@ FILE *fmemopen(void *restrict buf, size_t max_size, const char *restrict mode)
} else if (mode[0] == 'a') {
flags = O_WRONLY | O_CREAT | O_APPEND;
} else {
- free(f);
+ free(stream);
errno = EINVAL;
return NULL;
}
@@ -39,9 +42,9 @@ FILE *fmemopen(void *restrict buf, size_t max_size, const char *restrict mode)
flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
}
- f->flags = flags;
+ __IMPL(stream)->flags = flags;
- __libc_fadd(f);
+ __libc_fadd(stream);
- return f;
+ return stream;
}