aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2023-01-14 02:02:49 +0100
committerBen Hutchings <ben@decadent.org.uk>2023-02-12 22:10:18 +0100
commit5e8a2426ec3950742c4377be5bf6c72aa7312d59 (patch)
tree640af55ef687871d4886d3d07777d85c92f85d8b
parente3a0f7bae41eaf18c28c6731cc4961c426d0322d (diff)
downloadklibc-5e8a2426ec3950742c4377be5bf6c72aa7312d59.tar.gz
[klibc] utimes: Make all utimes calls wrappers for utimensat()
futimesat(), utime(), and utimes() don't have direct replacements that use 64-bit time on 32-bit architectures. Instead, we have to use the utimensat() system call which uses a different buffer structure. In preparation for using a 64-bit time everywhere: - Make utimensat() a required system call - Make futimesat(), utime(), and utimes() wrappers for utimensat() Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r--usr/klibc/Kbuild5
-rw-r--r--usr/klibc/SYSCALLS.def5
-rw-r--r--usr/klibc/futimesat.c18
-rw-r--r--usr/klibc/utime.c4
-rw-r--r--usr/klibc/utimes.c4
5 files changed, 22 insertions, 14 deletions
diff --git a/usr/klibc/Kbuild b/usr/klibc/Kbuild
index 85ebb25a0736bc..02a18e643fadc3 100644
--- a/usr/klibc/Kbuild
+++ b/usr/klibc/Kbuild
@@ -53,7 +53,8 @@ klib-y += vsnprintf.o snprintf.o vsprintf.o sprintf.o \
clearenv.o nullenv.o \
getopt.o getopt_long.o readdir.o scandir.o alphasort.o remove.o \
syslog.o closelog.o pty.o isatty.o reboot.o \
- time.o utime.o lseek.o nice.o getpriority.o \
+ time.o lseek.o nice.o getpriority.o \
+ futimesat.o utime.o utimes.o \
qsort.o bsearch.o \
lrand48.o jrand48.o mrand48.o nrand48.o srand48.o seed48.o \
inet/inet_ntoa.o inet/inet_aton.o inet/inet_addr.o \
@@ -61,7 +62,7 @@ klib-y += vsnprintf.o snprintf.o vsprintf.o sprintf.o \
accept.o send.o recv.o \
access.o chmod.o chown.o dup2.o mknod.o poll.o rename.o renameat.o \
fstat.o fstatat.o lstat.o stat.o \
- lchown.o link.o rmdir.o unlink.o utimes.o mkdir.o \
+ lchown.o link.o rmdir.o unlink.o mkdir.o \
readlink.o realpath.o select.o symlink.o pipe.o \
ctype/isalnum.o ctype/isalpha.o ctype/isascii.o \
ctype/isblank.o ctype/iscntrl.o ctype/isdigit.o \
diff --git a/usr/klibc/SYSCALLS.def b/usr/klibc/SYSCALLS.def
index 00c52e02b4e79d..2b23200af25288 100644
--- a/usr/klibc/SYSCALLS.def
+++ b/usr/klibc/SYSCALLS.def
@@ -140,10 +140,7 @@ int fchown32,fchown::fchown(int, uid_t, gid_t);
<?> int fchownat(int, const char *, uid_t, gid_t, int);
<?> int lchown32,lchown::lchown(const char *, uid_t, gid_t);
int getcwd::__getcwd(char *, size_t);
-<?> int utime(const char *, const struct utimbuf *);
-<?> int utimes(const char *, const struct timeval *);
-<?> int futimesat(int, const char *, const struct timeval *);
-<?> int utimensat(int, const char *, const struct timespec *, int);
+int utimensat(int, const char *, const struct timespec *, int);
<?> int inotify_init();
<?> int inotify_add_watch(int, const char *, __u32);
<?> int inotify_rm_watch(int, __u32);
diff --git a/usr/klibc/futimesat.c b/usr/klibc/futimesat.c
new file mode 100644
index 00000000000000..f4da4bad05c46a
--- /dev/null
+++ b/usr/klibc/futimesat.c
@@ -0,0 +1,18 @@
+#include <fcntl.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+
+int futimesat(int dirfd, const char *filename, const struct timeval tvp[2])
+{
+ struct timespec ts[2];
+
+ if (tvp) {
+ ts[0].tv_sec = tvp[0].tv_sec;
+ ts[0].tv_nsec = tvp[0].tv_usec * 1000;
+ ts[1].tv_sec = tvp[1].tv_sec;
+ ts[1].tv_nsec = tvp[1].tv_usec * 1000;
+ }
+
+ return utimensat(dirfd, filename, &ts[0], 0);
+}
diff --git a/usr/klibc/utime.c b/usr/klibc/utime.c
index cb8f50a0de0f0c..bfae2d9e90111e 100644
--- a/usr/klibc/utime.c
+++ b/usr/klibc/utime.c
@@ -7,8 +7,6 @@
#include <sys/types.h>
#include <sys/syscall.h>
-#ifndef __NR_utime
-
int utime(const char *filename, const struct utimbuf *buf)
{
struct timeval tvp[2];
@@ -20,5 +18,3 @@ int utime(const char *filename, const struct utimbuf *buf)
return utimes(filename, tvp);
}
-
-#endif
diff --git a/usr/klibc/utimes.c b/usr/klibc/utimes.c
index ce6d2f811a5421..74cb82264c702d 100644
--- a/usr/klibc/utimes.c
+++ b/usr/klibc/utimes.c
@@ -3,8 +3,6 @@
#include <sys/stat.h>
#include <sys/syscall.h>
-#ifndef __NR_utimes
-
int utimes(const char *file, const struct timeval tvp[2])
{
struct timespec ts[2];
@@ -18,5 +16,3 @@ int utimes(const char *file, const struct timeval tvp[2])
return utimensat(AT_FDCWD, file, &ts[0], 0);
}
-
-#endif /* __NR_utimes */