summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2021-03-29 00:35:00 +0200
committerAndreas Kling <kling@serenityos.org>2021-03-29 19:58:12 +0200
commit3c390d65e4fd634da0d3e13393ba5a335ea53cc4 (patch)
tree9e7c7f5b80ce48951e0fd780d5e97b66b9af4abb
parenteab151c9945d2f3e57101b80ba8a365adb345160 (diff)
downloadserenity-3c390d65e4fd634da0d3e13393ba5a335ea53cc4.zip
LibC: Implement utimes function
-rw-r--r--Userland/Libraries/LibC/sys/time.h1
-rw-r--r--Userland/Libraries/LibC/time.cpp11
2 files changed, 12 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/sys/time.h b/Userland/Libraries/LibC/sys/time.h
index 11faa3bdd4..e2ed678c8c 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 56ef7a3663..9331bbde13 100644
--- a/Userland/Libraries/LibC/time.cpp
+++ b/Userland/Libraries/LibC/time.cpp
@@ -35,6 +35,7 @@
#include <sys/times.h>
#include <syscall.h>
#include <time.h>
+#include <utime.h>
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));