summaryrefslogtreecommitdiff
path: root/src/user/lib/unistd.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/unistd.c
parent710e9b2b5c16f74f66420c66d12455ad518d42c7 (diff)
user/libc: camellia_open, takes cwd into account
Diffstat (limited to 'src/user/lib/unistd.c')
-rw-r--r--src/user/lib/unistd.c30
1 files changed, 7 insertions, 23 deletions
diff --git a/src/user/lib/unistd.c b/src/user/lib/unistd.c
index 04a060d..01aa94f 100644
--- a/src/user/lib/unistd.c
+++ b/src/user/lib/unistd.c
@@ -1,4 +1,4 @@
-#include <camellia/flags.h>
+#include <camellia.h>
#include <camellia/path.h>
#include <camellia/syscalls.h>
#include <errno.h>
@@ -24,24 +24,11 @@ _Noreturn void exit(int c) {
_Noreturn void _exit(int c) { exit(c); };
int unlink(const char *path) {
- size_t len = strlen(path) + 1;
- char *abspath = malloc(len);
- if (!abspath) return -1;
-
- size_t abslen = absolutepath(abspath, path, len);
- if (abslen == 0) { errno = EINVAL; goto err; }
-
- // TODO take cwd into account
- handle_t h = _syscall_open(abspath, abslen - 1, OPEN_WRITE);
- if (h < 0) { errno = -h; goto err; }
-
+ handle_t h = camellia_open(path, OPEN_WRITE);
+ if (h < 0) return errno = -h, -1;
long ret = _syscall_remove(h);
- if (ret < 0) { errno = -ret; goto err; }
-
+ if (ret < 0) return errno = -ret, -1;
return 0;
-err:
- free(abspath);
- return -1;
}
// TODO isatty
@@ -117,12 +104,9 @@ int chdir(const char *path) {
}
/* check if exists */
- h = _syscall_open(cwd2, strlen(cwd2), OPEN_READ);
- if (h < 0) {
- errno = ENOENT;
- return -1;
- }
- _syscall_close(h);
+ h = camellia_open(cwd2, OPEN_READ);
+ if (h < 0) return errno = ENOENT, -1;
+ close(h);
tmp = cwd;
cwd = cwd2;