mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:37:45 +00:00
LibCore: Add wrapper for fstatat()
`Core::System::fstatat()` is similar to our standard `Core::System` wrappers. `Core::Directory::stat(relative_path, flags)` is a convenience method if you already have a Directory, to stat a file relative to it.
This commit is contained in:
parent
c140b67be3
commit
da8da79e62
4 changed files with 24 additions and 1 deletions
|
@ -88,6 +88,11 @@ ErrorOr<NonnullOwnPtr<File>> Directory::open(StringView filename, File::OpenMode
|
||||||
return File::adopt_fd(fd, mode);
|
return File::adopt_fd(fd, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<struct stat> Directory::stat(StringView filename, int flags) const
|
||||||
|
{
|
||||||
|
return System::fstatat(m_directory_fd, filename, flags);
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<struct stat> Directory::stat() const
|
ErrorOr<struct stat> Directory::stat() const
|
||||||
{
|
{
|
||||||
return System::fstat(m_directory_fd);
|
return System::fstat(m_directory_fd);
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
static ErrorOr<Directory> adopt_fd(int fd, LexicalPath path);
|
static ErrorOr<Directory> adopt_fd(int fd, LexicalPath path);
|
||||||
|
|
||||||
ErrorOr<NonnullOwnPtr<File>> open(StringView filename, File::OpenMode mode) const;
|
ErrorOr<NonnullOwnPtr<File>> open(StringView filename, File::OpenMode mode) const;
|
||||||
|
ErrorOr<struct stat> stat(StringView filename, int flags) const;
|
||||||
ErrorOr<struct stat> stat() const;
|
ErrorOr<struct stat> stat() const;
|
||||||
int fd() const { return m_directory_fd; }
|
int fd() const { return m_directory_fd; }
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
|
||||||
* Copyright (c) 2021-2022, Kenneth Myhra <kennethmyhra@serenityos.org>
|
* Copyright (c) 2021-2022, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||||
* Copyright (c) 2022, Matthias Zimmerman <matthias291999@gmail.com>
|
* Copyright (c) 2022, Matthias Zimmerman <matthias291999@gmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
@ -380,6 +380,22 @@ ErrorOr<struct stat> fstat(int fd)
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<struct stat> fstatat(int fd, StringView path, int flags)
|
||||||
|
{
|
||||||
|
if (!path.characters_without_null_termination())
|
||||||
|
return Error::from_syscall("fstatat"sv, -EFAULT);
|
||||||
|
|
||||||
|
struct stat st = {};
|
||||||
|
#ifdef AK_OS_SERENITY
|
||||||
|
Syscall::SC_stat_params params { { path.characters_without_null_termination(), path.length() }, &st, fd, !(flags & AT_SYMLINK_NOFOLLOW) };
|
||||||
|
int rc = syscall(SC_stat, ¶ms);
|
||||||
|
#else
|
||||||
|
DeprecatedString path_string = path;
|
||||||
|
int rc = ::fstatat(fd, path_string.characters(), &st, flags);
|
||||||
|
#endif
|
||||||
|
HANDLE_SYSCALL_RETURN_VALUE("fstatat", rc, st);
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<int> fcntl(int fd, int command, ...)
|
ErrorOr<int> fcntl(int fd, int command, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
|
@ -116,6 +116,7 @@ ErrorOr<sig_t> signal(int signal, sig_t handler);
|
||||||
ErrorOr<sighandler_t> signal(int signal, sighandler_t handler);
|
ErrorOr<sighandler_t> signal(int signal, sighandler_t handler);
|
||||||
#endif
|
#endif
|
||||||
ErrorOr<struct stat> fstat(int fd);
|
ErrorOr<struct stat> fstat(int fd);
|
||||||
|
ErrorOr<struct stat> fstatat(int fd, StringView path, int flags);
|
||||||
ErrorOr<int> fcntl(int fd, int command, ...);
|
ErrorOr<int> fcntl(int fd, int command, ...);
|
||||||
ErrorOr<void*> mmap(void* address, size_t, int protection, int flags, int fd, off_t, size_t alignment = 0, StringView name = {});
|
ErrorOr<void*> mmap(void* address, size_t, int protection, int flags, int fd, off_t, size_t alignment = 0, StringView name = {});
|
||||||
ErrorOr<void> munmap(void* address, size_t);
|
ErrorOr<void> munmap(void* address, size_t);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue