diff --git a/user/app_relativepath.c b/user/app_relativepath.c index 2c7fa7e5138d21e045409ca7b42d17480e3e30d3..0787c4c6b4a3b90e6cc2008b63bae152296ed386 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 1c4f6d15aeb253e6c3abde07ef5196488df6faec..8eb160a94e16c013df11bc1b47294292e8034c65 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 95a686d04c251563f356ce75ef14942abaef019f..aa678e772fcd698981a52fd990ab64fcd1681859 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