From 5e8a2426ec3950742c4377be5bf6c72aa7312d59 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Sat, 14 Jan 2023 02:02:49 +0100 Subject: [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 --- usr/klibc/Kbuild | 5 +++-- usr/klibc/SYSCALLS.def | 5 +---- usr/klibc/futimesat.c | 18 ++++++++++++++++++ usr/klibc/utime.c | 4 ---- usr/klibc/utimes.c | 4 ---- 5 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 usr/klibc/futimesat.c 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 +#include +#include +#include + +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 #include -#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 #include -#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 */ -- cgit 1.2.3-korg