From 7b13f22f9619ea41af36fedfed5d886bc1bbdcb6 Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Sat, 27 Nov 2021 22:01:40 +0100 Subject: [PATCH] LibCore: Add syscall wrapper for clock_settime() --- Userland/Libraries/LibCore/System.cpp | 12 ++++++++++++ Userland/Libraries/LibCore/System.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 55801d6e91..a76d2a6da9 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -360,4 +360,16 @@ ErrorOr getgrnam(StringView name) return Error::from_string_literal("getgrnam: Unknown username"sv); } +ErrorOr clock_settime(clockid_t clock_id, struct timespec* ts) +{ +#ifdef __serenity__ + int rc = syscall(SC_clock_settime, clock_id, ts); + HANDLE_SYSCALL_RETURN_VALUE("clocksettime"sv, rc, {}); +#else + if (::clock_settime(clock_id, ts) < 0) + return Error::from_syscall("clocksettime"sv, -errno); + return {}; +#endif +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 0905fbb294..b04f89ae7a 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace Core::System { @@ -49,5 +50,6 @@ ErrorOr chmod(StringView pathname, mode_t mode); ErrorOr chown(StringView pathname, uid_t uid, gid_t gid); ErrorOr getpwnam(StringView name); ErrorOr getgrnam(StringView name); +ErrorOr clock_settime(clockid_t clock_id, struct timespec* ts); }