diff options
-rw-r--r-- | Userland/Libraries/LibCore/Directory.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/Directory.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/System.cpp | 18 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/System.h | 1 |
4 files changed, 24 insertions, 1 deletions
diff --git a/Userland/Libraries/LibCore/Directory.cpp b/Userland/Libraries/LibCore/Directory.cpp index cbfd048fc7..5509ee5947 100644 --- a/Userland/Libraries/LibCore/Directory.cpp +++ b/Userland/Libraries/LibCore/Directory.cpp @@ -88,6 +88,11 @@ ErrorOr<NonnullOwnPtr<File>> Directory::open(StringView filename, File::OpenMode 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 { return System::fstat(m_directory_fd); diff --git a/Userland/Libraries/LibCore/Directory.h b/Userland/Libraries/LibCore/Directory.h index ec04cc714a..44b1048d19 100644 --- a/Userland/Libraries/LibCore/Directory.h +++ b/Userland/Libraries/LibCore/Directory.h @@ -41,6 +41,7 @@ public: static ErrorOr<Directory> adopt_fd(int fd, LexicalPath path); ErrorOr<NonnullOwnPtr<File>> open(StringView filename, File::OpenMode mode) const; + ErrorOr<struct stat> stat(StringView filename, int flags) const; ErrorOr<struct stat> stat() const; int fd() const { return m_directory_fd; } diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 965f17a7a8..a277a5dd56 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -1,7 +1,7 @@ /* * Copyright (c) 2021-2022, Andreas Kling <kling@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> * * SPDX-License-Identifier: BSD-2-Clause @@ -380,6 +380,22 @@ ErrorOr<struct stat> fstat(int fd) 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, ...) { va_list ap; diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 444f37a540..7dba27fe6f 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -116,6 +116,7 @@ ErrorOr<sig_t> signal(int signal, sig_t handler); ErrorOr<sighandler_t> signal(int signal, sighandler_t handler); #endif ErrorOr<struct stat> fstat(int fd); +ErrorOr<struct stat> fstatat(int fd, StringView path, int flags); 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> munmap(void* address, size_t); |