feat(userspace/libc): implement fstatat, lstat & stat

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
EnderIce2 2025-02-20 02:17:19 +02:00
parent c83c542f5b
commit 8d08ab933a
No known key found for this signature in database
GPG Key ID: 2EE20AF089811A5A
2 changed files with 37 additions and 10 deletions

View File

@ -88,16 +88,16 @@ extern "C"
int fchmod(int, mode_t); int fchmod(int, mode_t);
int fchmodat(int, const char *, mode_t, int); int fchmodat(int, const char *, mode_t, int);
int fstat(int fildes, struct stat *buf); 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 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 mkdir(const char *path, mode_t mode);
int mkdirat(int fd, const char *path, mode_t mode); int mkdirat(int fd, const char *path, mode_t mode);
int mkfifo(const char *, mode_t); int mkfifo(const char *, mode_t);
int mkfifoat(int, const char *, mode_t); int mkfifoat(int, const char *, mode_t);
int mknod(const char *, mode_t, dev_t); int mknod(const char *, mode_t, dev_t);
int mknodat(int, 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); mode_t umask(mode_t);
int utimensat(int, const char *, const struct timespec[2], int); int utimensat(int, const char *, const struct timespec[2], int);

View File

@ -31,19 +31,35 @@ export int fstat(int fildes, struct stat *buf)
return -1; return -1;
} }
int result = call_fstat(fildes, buf); return __check_errno(call_fstat(fildes, buf), -1);
if (result == -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 -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 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) 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 mkfifoat(int, const char *, mode_t);
export int mknod(const char *, mode_t, dev_t); export int mknod(const char *, mode_t, dev_t);
export int mknodat(int, 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 mode_t umask(mode_t);
export int utimensat(int, const char *, const struct timespec[2], int); export int utimensat(int, const char *, const struct timespec[2], int);