From e83dca9817614d0dc77ce1e5dc13eed44b61eb2f Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 4 Oct 2022 13:59:21 +0200 Subject: user/libc: camellia_open, takes cwd into account --- src/user/lib/stdio/file.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'src/user/lib/stdio/file.c') diff --git a/src/user/lib/stdio/file.c b/src/user/lib/stdio/file.c index f3120d7..531d44b 100644 --- a/src/user/lib/stdio/file.c +++ b/src/user/lib/stdio/file.c @@ -1,5 +1,5 @@ #include "file.h" -#include +#include #include #include #include @@ -20,7 +20,6 @@ FILE *fopen(const char *path, const char *mode) { FILE *f; handle_t h; int flags = 0; - char *tmppath = NULL; if (!path) { errno = 1; return NULL; @@ -30,18 +29,10 @@ FILE *fopen(const char *path, const char *mode) { if (!strcmp(path, "stdin")) return file_clone(stdin, mode); if (!strcmp(path, "stdout")) return file_clone(stdout, mode); if (!strcmp(path, "stderr")) return file_clone(stderr, mode); - errno = 1; + errno = ENOENT; return NULL; } - if (path && path[0] != '/') { - size_t len = absolutepath(NULL, path, 0); - tmppath = malloc(len); - if (!tmppath) return NULL; - absolutepath(tmppath, path, len); - path = tmppath; - } - if (strchr(mode, 'e')) { /* camellia extension: open as executable */ flags |= OPEN_EXEC; @@ -53,12 +44,8 @@ FILE *fopen(const char *path, const char *mode) { flags |= OPEN_WRITE | OPEN_CREATE; } - h = _syscall_open(path, strlen(path), flags); - if (tmppath) free(tmppath); - if (h < 0) { - errno = -h; - return NULL; - } + h = camellia_open(path, flags); + if (h < 0) return NULL; if (mode[0] == 'w') _syscall_write(h, NULL, 0, 0, WRITE_TRUNCATE); -- cgit v1.2.3