summaryrefslogtreecommitdiff
path: root/lib/libc/time/utimes.c
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-07 20:10:31 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-07 20:10:31 +0100
commitfc00c656c96528112d05cf0edf8631bd5eaea446 (patch)
treea6e0e6c588191a8bd1c64afc3b7a258e3e66c236 /lib/libc/time/utimes.c
Add build system scaffolding and libc headers
Diffstat (limited to 'lib/libc/time/utimes.c')
-rw-r--r--lib/libc/time/utimes.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/libc/time/utimes.c b/lib/libc/time/utimes.c
new file mode 100644
index 00000000..d6448c76
--- /dev/null
+++ b/lib/libc/time/utimes.c
@@ -0,0 +1,25 @@
+#include <fcntl.h>
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+
+int utimes(const char *path, const struct timeval times[2])
+{
+ struct timespec ts[2];
+
+ if (times) {
+ if (times[0].tv_usec >= 1000000ULL ||
+ times[1].tv_usec >= 1000000ULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ ts[0].tv_sec = times[0].tv_sec;
+ ts[0].tv_nsec = times[0].tv_usec * 1000;
+ ts[1].tv_sec = times[1].tv_sec;
+ ts[1].tv_nsec = times[1].tv_usec * 1000;
+ }
+
+ return utimensat(AT_FDCWD, path, times ? ts : NULL, 0);
+}