Kernel/LibC: add SYS_STAT and stat(), lstat()

This commit is contained in:
Bananymous
2023-06-05 14:36:17 +03:00
parent 69b94dad00
commit d1ad38c8d4
10 changed files with 75 additions and 9 deletions

View File

@@ -10,6 +10,7 @@ set(LIBC_SOURCES
stdio.cpp
stdlib.cpp
string.cpp
sys/stat.cpp
sys/wait.cpp
termios.cpp
unistd.cpp

View File

@@ -22,6 +22,7 @@ __BEGIN_DECLS
#define SYS_EXEC 15
#define SYS_REALLOC 16
#define SYS_WAIT 17
#define SYS_STAT 18
__END_DECLS

14
libc/sys/stat.cpp Normal file
View File

@@ -0,0 +1,14 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <unistd.h>
int lstat(const char* __restrict path, struct stat* __restrict buf)
{
return syscall(SYS_STAT, path, buf, O_RDONLY | O_NOFOLLOW);
}
int stat(const char* __restrict path, struct stat* __restrict buf)
{
return syscall(SYS_STAT, path, buf, O_RDONLY);
}

View File

@@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <unistd.h>
@@ -145,6 +146,14 @@ long syscall(long syscall, ...)
ret = Kernel::syscall(SYS_WAIT, pid, (uintptr_t)stat_loc, options);
break;
}
case SYS_STAT:
{
const char* path = va_arg(args, const char*);
struct stat* buf = va_arg(args, struct stat*);
int flags = va_arg(args, int);
ret = Kernel::syscall(SYS_STAT, (uintptr_t)path, (uintptr_t)buf, flags);
break;
}
default:
puts("LibC: Unhandeled syscall");
ret = -ENOSYS;