LibC: Implement utimes function

This commit is contained in:
Jelle Raaijmakers 2021-03-29 00:35:00 +02:00 committed by Andreas Kling
parent eab151c994
commit 3c390d65e4
Notes: sideshowbarker 2024-07-18 20:58:10 +09:00
2 changed files with 12 additions and 0 deletions

View file

@ -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)
{

View file

@ -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));