From c83c542f5b2c451a0cdfab7578add96523123470 Mon Sep 17 00:00:00 2001 From: EnderIce2 Date: Thu, 20 Feb 2025 02:12:02 +0200 Subject: [PATCH] feat(userspace/libc): implement fstat() Signed-off-by: EnderIce2 --- Userspace/libc/include/sys/stat.h | 2 +- Userspace/libc/src/std/sys/stat.c | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Userspace/libc/include/sys/stat.h b/Userspace/libc/include/sys/stat.h index 92d4a560..8b64d068 100644 --- a/Userspace/libc/include/sys/stat.h +++ b/Userspace/libc/include/sys/stat.h @@ -87,7 +87,7 @@ extern "C" int chmod(const char *, mode_t); int fchmod(int, mode_t); int fchmodat(int, const char *, mode_t, int); - int fstat(int, struct stat *); + int fstat(int fildes, struct stat *buf); int fstatat(int, const char *restrict, struct stat *restrict, int); int futimens(int, const struct timespec[2]); int lstat(const char *restrict, struct stat *restrict); diff --git a/Userspace/libc/src/std/sys/stat.c b/Userspace/libc/src/std/sys/stat.c index 6de4f2d3..6b2411d8 100644 --- a/Userspace/libc/src/std/sys/stat.c +++ b/Userspace/libc/src/std/sys/stat.c @@ -22,7 +22,25 @@ export int chmod(const char *, mode_t); export int fchmod(int, mode_t); export int fchmodat(int, const char *, mode_t, int); -export int fstat(int, struct stat *); + +export int fstat(int fildes, struct stat *buf) +{ + if (fildes < 0) + { + errno = EBADF; + return -1; + } + + int result = call_fstat(fildes, buf); + if (result == -1) + { + errno = result; + return -1; + } + + return 0; +} + 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);