From c920ea363635ae03e3c3575271d9acbe29d63e6d Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Wed, 30 Apr 2025 10:50:37 -0400 Subject: inflate / deflate --- user/lib/fopen.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 user/lib/fopen.c (limited to 'user/lib/fopen.c') diff --git a/user/lib/fopen.c b/user/lib/fopen.c new file mode 100644 index 0000000..cb2529f --- /dev/null +++ b/user/lib/fopen.c @@ -0,0 +1,37 @@ +#include +#include + +FILE *fopen(const char *restrict filename, const char *restrict modes) +{ + int flags = 0; + int fd; + + char c; + while (c = *modes, c) { + switch (c) { + case 'r': + flags |= O_RDONLY; + break; + case 'w': + flags |= O_CREATE | O_WRONLY; + break; + case 'a': + flags |= O_APPEND; + break; + case '+': + flags |= O_RDWR; + break; + default: + return NULL; + } + } + + if (flags == 0) + return NULL; + + fd = open(filename, flags); + if (fd < 0) + return NULL; + + return (FILE *)(uintptr_t)fd; +} -- cgit v1.2.3-freya