From 975665ffa644808c9f8c383dae6094e285ba7f1b Mon Sep 17 00:00:00 2001 From: Zhiyuan Shao Date: Wed, 8 Feb 2023 08:53:16 +0800 Subject: [PATCH] revise app and user lib --- user/app_relativepath.c | 11 +++++++++++ user/user_lib.c | 14 ++++++++++++++ user/user_lib.h | 2 ++ 3 files changed, 27 insertions(+) diff --git a/user/app_relativepath.c b/user/app_relativepath.c index 2c7fa7e..0787c4c 100644 --- a/user/app_relativepath.c +++ b/user/app_relativepath.c @@ -2,6 +2,17 @@ #include "util/string.h" #include "util/types.h" +void pwd() { + char path[30]; + read_cwd(path); + printu("cwd:%s\n", path); +} + +void cd(const char *path) { + if (change_cwd(path) != 0) + printu("cd failed\n"); +} + int main(int argc, char *argv[]) { int fd; int MAXBUF = 512; diff --git a/user/user_lib.c b/user/user_lib.c index 1c4f6d1..8eb160a 100644 --- a/user/user_lib.c +++ b/user/user_lib.c @@ -167,3 +167,17 @@ int unlink_u(const char *fn){ int close(int fd) { return do_user_call(SYS_user_close, fd, 0, 0, 0, 0, 0, 0); } + +// +// lib call to read present working directory (pwd) +// +int read_cwd(char *path) { + return do_user_call(SYS_user_rcwd, (uint64)path, 0, 0, 0, 0, 0, 0); +} + +// +// lib call to change pwd +// +int change_cwd(const char *path) { + return do_user_call(SYS_user_ccwd, (uint64)path, 0, 0, 0, 0, 0, 0); +} diff --git a/user/user_lib.h b/user/user_lib.h index 95a686d..aa678e7 100644 --- a/user/user_lib.h +++ b/user/user_lib.h @@ -33,5 +33,7 @@ int closedir_u(int fd); int link_u(const char *fn1, const char *fn2); int unlink_u(const char *fn); +int read_cwd(char *path); +int change_cwd(const char *path); #endif -- GitLab