Kernel/LibC: add SYS_STAT and stat(), lstat()
This commit is contained in:
@@ -10,6 +10,7 @@ set(LIBC_SOURCES
|
||||
stdio.cpp
|
||||
stdlib.cpp
|
||||
string.cpp
|
||||
sys/stat.cpp
|
||||
sys/wait.cpp
|
||||
termios.cpp
|
||||
unistd.cpp
|
||||
|
||||
@@ -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
14
libc/sys/stat.cpp
Normal 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);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user