From bd8f10db80342757cc920c0d54a58d2b46f31b7a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 20 Dec 2021 19:48:30 +0100 Subject: [PATCH] LibCore: Add syscall wrapper for utime() --- Userland/Libraries/LibCore/System.cpp | 19 +++++++++++++++++++ Userland/Libraries/LibCore/System.h | 1 + 2 files changed, 20 insertions(+) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index c572f56367..465a936309 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -537,4 +537,23 @@ ErrorOr rename(StringView old_path, StringView new_path) #endif } +ErrorOr utime(StringView path, Optional maybe_buf) +{ + if (path.is_null()) + return Error::from_errno(EFAULT); + + struct utimbuf* buf = nullptr; + if (maybe_buf.has_value()) + buf = &maybe_buf.value(); +#ifdef __serenity__ + int rc = syscall(SC_utime, path.characters_without_null_termination(), path.length(), buf); + HANDLE_SYSCALL_RETURN_VALUE("utime"sv, rc, {}); +#else + String path_string = path; + if (::utime(path.characters(), buf) < 0) + return Error::from_syscall("utime"sv, -errno); + return {}; +#endif +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index bb9f857c33..7e582c2bfb 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -73,5 +73,6 @@ ErrorOr fork(); ErrorOr mkstemp(Span pattern); ErrorOr fchmod(int fd, mode_t mode); ErrorOr rename(StringView old_path, StringView new_path); +ErrorOr utime(StringView path, Optional); }