diff options
author | Ryo Nakamura <upa@haeena.net> | 2024-02-06 16:15:43 +0900 |
---|---|---|
committer | Ryo Nakamura <upa@haeena.net> | 2024-02-06 16:15:43 +0900 |
commit | a7f8ad948b38c450c0f9ccd52185771ae8f9754e (patch) | |
tree | c480252f0a26dca743d1c81818dec6f6a660f29e /src/platform.c | |
parent | ff45d9d71b85a618aed6d3d5e5056bada6ff81f9 (diff) |
add -p option, preserving file timestamps
Diffstat (limited to 'src/platform.c')
-rw-r--r-- | src/platform.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/platform.c b/src/platform.c index a2dfb86..668c571 100644 --- a/src/platform.c +++ b/src/platform.c @@ -2,14 +2,21 @@ #ifdef __APPLE__ #include <stdlib.h> #include <sys/types.h> +#include <sys/time.h> #include <sys/sysctl.h> #elif linux #define _GNU_SOURCE -#include <sched.h> #include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sched.h> #elif __FreeBSD__ #include <stdlib.h> #include <unistd.h> +#include <sys/stat.h> +#include <fcntl.h> #include <pthread_np.h> #else #error unsupported platform @@ -40,6 +47,20 @@ int set_thread_affinity(pthread_t tid, int core) return 0; } +int setutimes(const char *path, struct timespec atime, struct timespec mtime) +{ + struct timeval tv[2] = { + { + .tv_sec = atime.tv_sec, + .tv_usec = atime.tv_nsec * 1000, + }, + { + .tv_sec = mtime.tv_sec, + .tv_usec = mtime.tv_nsec * 1000, + }, + }; + return utimes(path, tv); +} static void random_string(char *buf, size_t size) { @@ -108,6 +129,19 @@ int set_thread_affinity(pthread_t tid, int core) return ret; } +int setutimes(const char *path, struct timespec atime, struct timespec mtime) +{ + struct timespec ts[2] = { atime, mtime }; + int fd = open(path, O_WRONLY); + int ret; + + if (fd < 0) + return -1; + ret = futimens(fd, ts); + close(fd); + return ret; +} + sem_t *sem_create(int value) { sem_t *sem; |