From fc00c656c96528112d05cf0edf8631bd5eaea446 Mon Sep 17 00:00:00 2001 From: Kacper Date: Sun, 7 Dec 2025 20:10:31 +0100 Subject: Add build system scaffolding and libc headers --- lib/libc/stdio/fmemopen.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/libc/stdio/fmemopen.c (limited to 'lib/libc/stdio/fmemopen.c') diff --git a/lib/libc/stdio/fmemopen.c b/lib/libc/stdio/fmemopen.c new file mode 100644 index 00000000..1ad86f7b --- /dev/null +++ b/lib/libc/stdio/fmemopen.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include +#include + +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)); + + if (f == NULL) + return f; + + f->fd = -1; + f->buf = buf; + f->buf_size = max_size; + f->type = _IOFBF; + + if (mode[0] == 'r') { + flags = O_RDONLY; + } else if (mode[0] == 'w') { + flags = O_WRONLY | O_CREAT | O_TRUNC; + } else if (mode[0] == 'a') { + flags = O_WRONLY | O_CREAT | O_APPEND; + } else { + errno = EINVAL; + return NULL; + } + + if (strchr(mode, '+')) { + flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR; + } + + f->flags = flags; + + __libc_fadd(f); + + return f; +} -- cgit v1.2.3