From 8d08ab933ac893364f024131473676c8aea29c07 Mon Sep 17 00:00:00 2001 From: EnderIce2 Date: Thu, 20 Feb 2025 02:17:19 +0200 Subject: [PATCH] feat(userspace/libc): implement fstatat, lstat & stat Signed-off-by: EnderIce2 --- Userspace/libc/include/sys/stat.h | 6 ++--- Userspace/libc/src/std/sys/stat.c | 41 +++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/Userspace/libc/include/sys/stat.h b/Userspace/libc/include/sys/stat.h index 8b64d068..7075b315 100644 --- a/Userspace/libc/include/sys/stat.h +++ b/Userspace/libc/include/sys/stat.h @@ -88,16 +88,16 @@ extern "C" int fchmod(int, mode_t); int fchmodat(int, const char *, mode_t, int); int fstat(int fildes, struct stat *buf); - int fstatat(int, const char *restrict, struct stat *restrict, int); + int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag); int futimens(int, const struct timespec[2]); - int lstat(const char *restrict, struct stat *restrict); + int lstat(const char *restrict path, struct stat *restrict buf); int mkdir(const char *path, mode_t mode); int mkdirat(int fd, const char *path, mode_t mode); int mkfifo(const char *, mode_t); int mkfifoat(int, const char *, mode_t); int mknod(const char *, mode_t, dev_t); int mknodat(int, const char *, mode_t, dev_t); - int stat(const char *restrict, struct stat *restrict); + int stat(const char *restrict path, struct stat *restrict buf); mode_t umask(mode_t); int utimensat(int, const char *, const struct timespec[2], int); diff --git a/Userspace/libc/src/std/sys/stat.c b/Userspace/libc/src/std/sys/stat.c index 6b2411d8..78fc60ce 100644 --- a/Userspace/libc/src/std/sys/stat.c +++ b/Userspace/libc/src/std/sys/stat.c @@ -31,19 +31,35 @@ export int fstat(int fildes, struct stat *buf) return -1; } - int result = call_fstat(fildes, buf); - if (result == -1) + return __check_errno(call_fstat(fildes, buf), -1); +} + +export int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag) +{ + if (fd < 0 || path == NULL || buf == NULL) { - errno = result; + errno = EBADF; return -1; } - return 0; + /* FIXME: fstatat is not implemented in kernel */ + + return __check_errno(ENOSYS, -1); + // return__check_errno(call_fstatat(fd, path, buf, flag), -1); } -export int fstatat(int, const char *restrict, struct stat *restrict, int); export int futimens(int, const struct timespec[2]); -export int lstat(const char *restrict, struct stat *restrict); + +export int lstat(const char *restrict path, struct stat *restrict buf) +{ + if (path == NULL || buf == NULL) + { + errno = EINVAL; + return -1; + } + + return __check_errno(call_lstat(path, buf), -1); +} export int mkdir(const char *path, mode_t mode) { @@ -60,6 +76,17 @@ export int mkfifo(const char *, mode_t); export int mkfifoat(int, const char *, mode_t); export int mknod(const char *, mode_t, dev_t); export int mknodat(int, const char *, mode_t, dev_t); -export int stat(const char *restrict, struct stat *restrict); + +export int stat(const char *restrict path, struct stat *restrict buf) +{ + if (path == NULL || buf == NULL) + { + errno = EINVAL; + return -1; + } + + return __check_errno(call_stat(path, buf), -1); +} + export mode_t umask(mode_t); export int utimensat(int, const char *, const struct timespec[2], int);