Kernel/LibC: Implement all stat family functions with fstatat

This patch gets rid of 2 unnecessary syscalls!
This commit is contained in:
2024-09-17 16:27:11 +03:00
parent 708a720d9d
commit f1a4bbce53
4 changed files with 28 additions and 52 deletions

View File

@@ -20,7 +20,6 @@ __BEGIN_DECLS
O(SYS_EXEC, exec) \
O(SYS_SLEEP, sleep) \
O(SYS_WAIT, wait) \
O(SYS_FSTAT, fstat) \
O(SYS_READ_DIR, readdir) \
O(SYS_SET_UID, setuid) \
O(SYS_SET_GID, setgid) \
@@ -47,7 +46,6 @@ __BEGIN_DECLS
O(SYS_FCNTL, fcntl) \
O(SYS_NANOSLEEP, nanosleep) \
O(SYS_FSTATAT, fstatat) \
O(SYS_STAT, stat) \
O(SYS_SYNC, sync) \
O(SYS_MMAP, mmap) \
O(SYS_MUNMAP, munmap) \

View File

@@ -1,6 +1,5 @@
#include <BAN/Assert.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
@@ -20,7 +19,7 @@ int fchmod(int fildes, mode_t mode)
int fstat(int fildes, struct stat* buf)
{
return syscall(SYS_FSTAT, fildes, buf);
return fstatat(fildes, nullptr, buf, 0);
}
int fstatat(int fd, const char* __restrict path, struct stat* __restrict buf, int flag)
@@ -30,12 +29,12 @@ int fstatat(int fd, const char* __restrict path, struct stat* __restrict buf, in
int lstat(const char* __restrict path, struct stat* __restrict buf)
{
return syscall(SYS_STAT, path, buf, AT_SYMLINK_NOFOLLOW);
return fstatat(AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW);
}
int stat(const char* __restrict path, struct stat* __restrict buf)
{
return syscall(SYS_STAT, path, buf, 0);
return fstatat(AT_FDCWD, path, buf, 0);
}
mode_t umask(mode_t cmask)