From 1640445cb2f5027eebbce90faf5273cff85ed844 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 2 Dec 2021 22:41:40 +0100 Subject: [PATCH] LibCore: Add lstat() syscall wrapper --- Userland/Libraries/LibCore/System.cpp | 18 ++++++++++++++++++ Userland/Libraries/LibCore/System.h | 1 + 2 files changed, 19 insertions(+) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index a08d1bcff2..c22ec3de4d 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -175,6 +175,24 @@ ErrorOr stat(StringView path) #endif } +ErrorOr lstat(StringView path) +{ + if (!path.characters_without_null_termination()) + return Error::from_syscall("lstat"sv, -EFAULT); + + struct stat st = {}; +#ifdef __serenity__ + Syscall::SC_stat_params params { { path.characters_without_null_termination(), path.length() }, &st, AT_FDCWD, false }; + int rc = syscall(SC_stat, ¶ms); + HANDLE_SYSCALL_RETURN_VALUE("lstat"sv, rc, st); +#else + String path_string = path; + if (::stat(path_string.characters(), &st) < 0) + return Error::from_syscall("lstat"sv, -errno); + return st; +#endif +} + ErrorOr read(int fd, Bytes buffer) { ssize_t rc = ::read(fd, buffer.data(), buffer.size()); diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 6f4fa49f7c..8bda871631 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -30,6 +30,7 @@ ErrorOr open(StringView path, int options, ...); ErrorOr close(int fd); ErrorOr ftruncate(int fd, off_t length); ErrorOr stat(StringView path); +ErrorOr lstat(StringView path); ErrorOr read(int fd, Bytes buffer); ErrorOr write(int fd, ReadonlyBytes buffer); ErrorOr kill(pid_t, int signal);