From: Waldemar Kozaczuk <[email protected]> Committer: Waldemar Kozaczuk <[email protected]> Branch: master
syscall: implement getcwd #Refs 1188 Signed-off-by: Waldemar Kozaczuk <[email protected]> --- diff --git a/linux.cc b/linux.cc --- a/linux.cc +++ b/linux.cc @@ -366,6 +366,20 @@ static int sys_exit_group(int ret) return 0; } +#define __NR_sys_getcwd __NR_getcwd +static long sys_getcwd(char *buf, unsigned long size) +{ + if (!buf) { + errno = EINVAL; + return -1; + } + auto ret = getcwd(buf, size); + if (!ret) { + return -1; + } + return strlen(ret) + 1; +} + #define __NR_sys_ioctl __NR_ioctl // // We need to define explicit sys_ioctl that takes these 3 parameters to conform @@ -482,6 +496,7 @@ OSV_LIBC_API long syscall(long number, ...) SYSCALL2(nanosleep, const struct timespec*, struct timespec *); SYSCALL4(fstatat, int, const char *, struct stat *, int); SYSCALL1(sys_exit_group, int); + SYSCALL2(sys_getcwd, char *, unsigned long); SYSCALL4(readlinkat, int, const char *, char *, size_t); SYSCALL0(getpid); SYSCALL3(set_mempolicy, int, unsigned long *, unsigned long); diff --git a/tests/tst-syscall.cc b/tests/tst-syscall.cc --- a/tests/tst-syscall.cc +++ b/tests/tst-syscall.cc @@ -13,6 +13,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <string.h> #include <iostream> @@ -117,6 +118,12 @@ int main(int argc, char **argv) assert(close(fd) == 0); + assert(chdir("/proc") == 0); + unsigned long size = 4096; + char path[size]; + assert(syscall(__NR_getcwd, path, size) == 6); + assert(strcmp("/proc", path) == 0); + // test that unknown system call results in a ENOSYS (see issue #757) expect_errno_l(syscall(999), ENOSYS); -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/0000000000002417f305dfffc654%40google.com.
