From 3c390d65e4fd634da0d3e13393ba5a335ea53cc4 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Mon, 29 Mar 2021 00:35:00 +0200 Subject: [PATCH] LibC: Implement utimes function --- Userland/Libraries/LibC/sys/time.h | 1 + Userland/Libraries/LibC/time.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/Userland/Libraries/LibC/sys/time.h b/Userland/Libraries/LibC/sys/time.h index 11faa3bdd47..e2ed678c8ce 100644 --- a/Userland/Libraries/LibC/sys/time.h +++ b/Userland/Libraries/LibC/sys/time.h @@ -45,6 +45,7 @@ struct timezone { int adjtime(const struct timeval* delta, struct timeval* old_delta); int gettimeofday(struct timeval* __restrict__, void* __restrict__) __attribute__((nonnull(1))); int settimeofday(struct timeval* __restrict__, void* __restrict__) __attribute__((nonnull(1))); +int utimes(const char* pathname, const struct timeval[2]); static inline void timeradd(const struct timeval* a, const struct timeval* b, struct timeval* out) { diff --git a/Userland/Libraries/LibC/time.cpp b/Userland/Libraries/LibC/time.cpp index 56ef7a36631..9331bbde132 100644 --- a/Userland/Libraries/LibC/time.cpp +++ b/Userland/Libraries/LibC/time.cpp @@ -35,6 +35,7 @@ #include #include #include +#include extern "C" { @@ -68,6 +69,16 @@ int settimeofday(struct timeval* __restrict__ tv, void* __restrict__) return clock_settime(CLOCK_REALTIME, &ts); } +int utimes(const char* pathname, const struct timeval times[2]) +{ + if (!times) { + return utime(pathname, nullptr); + } + // FIXME: implement support for tv_usec in the utime (or a new) syscall + utimbuf buf = { times[0].tv_sec, times[1].tv_sec }; + return utime(pathname, &buf); +} + char* ctime(const time_t* t) { return asctime(localtime(t));