Kernel/LibC: Implement utime* family functions

This patch adds *working*
 - utime
 - utimes
 - utimensat
 - futimens
This commit is contained in:
2025-05-29 05:01:26 +03:00
parent 8392472bac
commit 1bd454b8fd
13 changed files with 150 additions and 20 deletions

View File

@@ -94,6 +94,7 @@ __BEGIN_DECLS
O(SYS_FSYNC, fsync) \
O(SYS_SYMLINKAT, symlinkat) \
O(SYS_HARDLINKAT, hardlinkat) \
O(SYS_UTIMENSAT, utimensat) \
O(SYS_YIELD, yield) \
O(SYS_SET_TLS, set_tls) \
O(SYS_GET_TLS, get_tls) \

View File

@@ -53,3 +53,13 @@ int mkdir(const char* path, mode_t mode)
{
return syscall(SYS_CREATE_DIR, path, __UMASKED_MODE(mode));
}
int futimens(int fd, const struct timespec times[2])
{
return utimensat(fd, nullptr, times, 0);
}
int utimensat(int fd, const char* path, const struct timespec times[2], int flag)
{
return syscall(SYS_UTIMENSAT, fd, path, times, flag);
}

View File

@@ -1,3 +1,4 @@
#include <fcntl.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <time.h>
@@ -26,3 +27,20 @@ int setitimer(int which, const struct itimerval* __restrict value, struct itimer
{
return syscall(SYS_SETITIMER, which, value, ovalue);
}
int utimes(const char* path, const struct timeval times[2])
{
if (times == nullptr)
return utimensat(AT_FDCWD, path, nullptr, 0);
const timespec times_ts[2] {
timespec {
.tv_sec = times[0].tv_sec,
.tv_nsec = times[0].tv_usec * 1000,
},
timespec {
.tv_sec = times[1].tv_sec,
.tv_nsec = times[1].tv_usec * 1000,
},
};
return utimensat(AT_FDCWD, path, times_ts, 0);
}

View File

@@ -1,11 +1,20 @@
#include <utime.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <utime.h>
int utime(const char* filename, const struct utimbuf* times)
{
fprintf(stddbg, "TODO: utime(\"%s\", %p)\n", filename, times);
struct stat st;
return stat(filename, &st);
if (times == nullptr)
return utimensat(AT_FDCWD, filename, nullptr, 0);
const timespec times_ts[2] {
timespec {
.tv_sec = times->actime,
.tv_nsec = 0,
},
timespec {
.tv_sec = times->modtime,
.tv_nsec = 0,
},
};
return utimensat(AT_FDCWD, filename, times_ts, 0);
}