Prechádzať zdrojové kódy

LibC: Implement utimes function

Jelle Raaijmakers 4 rokov pred
rodič
commit
3c390d65e4

+ 1 - 0
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)
 {

+ 11 - 0
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));