Kernel/LibC: add SYS_{SET,GET}_PWD and chdir, getpwd

This commit is contained in:
Bananymous
2023-06-12 01:24:46 +03:00
parent 7aeb8e4d36
commit f09b82c4b5
5 changed files with 92 additions and 0 deletions

View File

@@ -36,6 +36,8 @@ __BEGIN_DECLS
#define SYS_GET_GID 29
#define SYS_GET_EUID 30
#define SYS_GET_EGID 31
#define SYS_GET_PWD 32
#define SYS_SET_PWD 33
__END_DECLS

View File

@@ -233,6 +233,19 @@ long syscall(long syscall, ...)
ret = Kernel::syscall(SYS_GET_EGID);
break;
}
case SYS_GET_PWD:
{
char* buffer = va_arg(args, char*);
size_t size = va_arg(args, size_t);
ret = Kernel::syscall(SYS_GET_PWD, (uintptr_t)buffer, size);
break;
}
case SYS_SET_PWD:
{
const char* path = va_arg(args, const char*);
ret = Kernel::syscall(SYS_SET_PWD, (uintptr_t)path);
break;
}
default:
puts("LibC: Unhandeled syscall");
ret = -ENOSYS;
@@ -342,6 +355,26 @@ unsigned int sleep(unsigned int seconds)
return syscall(SYS_SLEEP, seconds);
}
char* getcwd(char* buf, size_t size)
{
if (size == 0)
{
errno = EINVAL;
return nullptr;
}
if ((char*)syscall(SYS_GET_PWD, buf, size) == nullptr)
return nullptr;
setenv("PWD", buf, 1);
return buf;
}
int chdir(const char* path)
{
return syscall(SYS_SET_PWD, path);
}
uid_t getuid(void)
{
return syscall(SYS_GET_UID);