56 lines
1.6 KiB
C++
56 lines
1.6 KiB
C++
#include <fcntl.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/time.h>
|
|
#include <utime.h>
|
|
|
|
extern "C"
|
|
{
|
|
int utime(const char* path, const struct utimbuf* buf)
|
|
{
|
|
if (!buf) return utimensat(AT_FDCWD, path, nullptr, 0);
|
|
|
|
struct timespec times[2] = {
|
|
{ .tv_sec = buf->actime, .tv_nsec = 0 },
|
|
{ .tv_sec = buf->modtime, .tv_nsec = 0 },
|
|
};
|
|
|
|
return utimensat(AT_FDCWD, path, times, 0);
|
|
}
|
|
|
|
int utimes(const char* path, const struct timeval* buf)
|
|
{
|
|
if (!buf) return utimensat(AT_FDCWD, path, nullptr, 0);
|
|
|
|
struct timespec times[2] = {
|
|
{ .tv_sec = buf[0].tv_sec, .tv_nsec = buf[0].tv_usec * 1000 },
|
|
{ .tv_sec = buf[1].tv_sec, .tv_nsec = buf[1].tv_usec * 1000 },
|
|
};
|
|
|
|
return utimensat(AT_FDCWD, path, times, 0);
|
|
}
|
|
|
|
int futimes(int fd, const struct timeval* buf)
|
|
{
|
|
if (!buf) return utimensat(fd, "", nullptr, AT_EMPTY_PATH);
|
|
|
|
struct timespec times[2] = {
|
|
{ .tv_sec = buf[0].tv_sec, .tv_nsec = buf[0].tv_usec * 1000 },
|
|
{ .tv_sec = buf[1].tv_sec, .tv_nsec = buf[1].tv_usec * 1000 },
|
|
};
|
|
|
|
return utimensat(fd, "", times, AT_EMPTY_PATH);
|
|
}
|
|
|
|
int lutimes(const char* path, const struct timeval* buf)
|
|
{
|
|
if (!buf) return utimensat(AT_FDCWD, path, nullptr, AT_SYMLINK_NOFOLLOW);
|
|
|
|
struct timespec times[2] = {
|
|
{ .tv_sec = buf[0].tv_sec, .tv_nsec = buf[0].tv_usec * 1000 },
|
|
{ .tv_sec = buf[1].tv_sec, .tv_nsec = buf[1].tv_usec * 1000 },
|
|
};
|
|
|
|
return utimensat(AT_FDCWD, path, times, AT_SYMLINK_NOFOLLOW);
|
|
}
|
|
}
|