summaryrefslogtreecommitdiff
path: root/src/user/lib/stdio
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/stdio
parent710e9b2b5c16f74f66420c66d12455ad518d42c7 (diff)
user/libc: camellia_open, takes cwd into account
Diffstat (limited to 'src/user/lib/stdio')
-rw-r--r--src/user/lib/stdio/file.c21
1 files changed, 4 insertions, 17 deletions
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 <camellia/flags.h>
+#include <camellia.h>
#include <camellia/syscalls.h>
#include <errno.h>
#include <stdio.h>
@@ -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);