summaryrefslogtreecommitdiff
path: root/src/user/lib/camellia.c
diff options
context:
space:
mode:
authordzwdz2022-10-04 13:59:21 +0200
committerdzwdz2022-10-04 13:59:21 +0200
commite83dca9817614d0dc77ce1e5dc13eed44b61eb2f (patch)
tree71bcb994d9cb4199cb002d39c06769f38be1ece2 /src/user/lib/camellia.c
parent710e9b2b5c16f74f66420c66d12455ad518d42c7 (diff)
user/libc: camellia_open, takes cwd into account
Diffstat (limited to 'src/user/lib/camellia.c')
-rw-r--r--src/user/lib/camellia.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/user/lib/camellia.c b/src/user/lib/camellia.c
new file mode 100644
index 0000000..1aa8402
--- /dev/null
+++ b/src/user/lib/camellia.c
@@ -0,0 +1,30 @@
+#include <camellia.h>
+#include <camellia/syscalls.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+handle_t camellia_open(const char *path, int flags) {
+ handle_t ret;
+ char *buf;
+ size_t len;
+
+ if (path == NULL)
+ return errno = EINVAL, -EINVAL;
+ if (flags & OPEN_CREATE)
+ flags |= OPEN_WRITE;
+
+ len = absolutepath(NULL, path, 0);
+ buf = malloc(len);
+ if (!buf)
+ return -errno;
+ absolutepath(buf, path, len);
+ ret = _syscall_open(buf, strlen(buf), flags);
+ free(buf);
+
+ if (ret < 0)
+ errno = -ret;
+
+ return ret;
+}