mirror of
https://github.com/upa/mscp.git
synced 2026-02-15 09:44:43 +08:00
add -p option, preserving file timestamps
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user