mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:27:46 +00:00
Kernel+LibC: Add fstatat
The function fstatat can do the same thing as the stat and lstat functions. However, it can be passed the file descriptor of a directory which will be used when as the starting point for relative paths. This is contrary to stat and lstat which use the current working directory as the starting for relative paths.
This commit is contained in:
parent
875116c3e5
commit
e7310ba45a
6 changed files with 29 additions and 5 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -50,25 +51,25 @@ int mkfifo(const char* pathname, mode_t mode)
|
|||
return mknod(pathname, mode | S_IFIFO, 0);
|
||||
}
|
||||
|
||||
static int do_stat(const char* path, struct stat* statbuf, bool follow_symlinks)
|
||||
static int do_stat(int dirfd, const char* path, struct stat* statbuf, bool follow_symlinks)
|
||||
{
|
||||
if (!path) {
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
Syscall::SC_stat_params params { { path, strlen(path) }, statbuf, follow_symlinks };
|
||||
Syscall::SC_stat_params params { dirfd, { path, strlen(path) }, statbuf, follow_symlinks };
|
||||
int rc = syscall(SC_stat, ¶ms);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int lstat(const char* path, struct stat* statbuf)
|
||||
{
|
||||
return do_stat(path, statbuf, false);
|
||||
return do_stat(AT_FDCWD, path, statbuf, false);
|
||||
}
|
||||
|
||||
int stat(const char* path, struct stat* statbuf)
|
||||
{
|
||||
return do_stat(path, statbuf, true);
|
||||
return do_stat(AT_FDCWD, path, statbuf, true);
|
||||
}
|
||||
|
||||
int fstat(int fd, struct stat* statbuf)
|
||||
|
@ -76,4 +77,9 @@ int fstat(int fd, struct stat* statbuf)
|
|||
int rc = syscall(SC_fstat, fd, statbuf);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int fstatat(int fd, const char* path, struct stat* statbuf, int flags)
|
||||
{
|
||||
return do_stat(fd, path, statbuf, !(flags & AT_SYMLINK_NOFOLLOW));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue