* We support the timespec stat times, so why not allowing the user to set
the times with higher resolution as well? git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32814 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,25 +1,47 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Axel Dörfler, [email protected].
|
* Copyright 2006-2009, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <utime.h>
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <NodeMonitor.h>
|
||||||
|
|
||||||
|
#include <syscalls.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define RETURN_AND_SET_ERRNO(err) \
|
||||||
|
if (err < 0) { \
|
||||||
|
errno = err; \
|
||||||
|
return -1; \
|
||||||
|
} \
|
||||||
|
return err;
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
utimes(const char *file, const struct timeval times[2])
|
utimes(const char* path, const struct timeval times[2])
|
||||||
{
|
{
|
||||||
struct utimbuf buffer, *timeBuffer;
|
struct stat stat;
|
||||||
|
status_t status;
|
||||||
|
|
||||||
if (times != NULL) {
|
if (times != NULL) {
|
||||||
timeBuffer = &buffer;
|
stat.st_atim.tv_sec = times[0].tv_sec;
|
||||||
buffer.actime = times[0].tv_sec + times[0].tv_usec / 1000000LL;
|
stat.st_atim.tv_nsec = times[0].tv_usec * 1000;
|
||||||
buffer.modtime = times[1].tv_sec + times[1].tv_usec / 1000000LL;
|
|
||||||
} else
|
|
||||||
timeBuffer = NULL;
|
|
||||||
|
|
||||||
return utime(file, timeBuffer);
|
stat.st_mtim.tv_sec = times[1].tv_sec;
|
||||||
|
stat.st_mtim.tv_nsec = times[1].tv_usec * 1000;
|
||||||
|
} else {
|
||||||
|
bigtime_t now = real_time_clock_usecs();
|
||||||
|
stat.st_atim.tv_sec = stat.st_mtim.tv_sec = now / 1000000;
|
||||||
|
stat.st_atim.tv_nsec = stat.st_mtim.tv_nsec = (now % 1000000) * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat),
|
||||||
|
B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME);
|
||||||
|
|
||||||
|
RETURN_AND_SET_ERRNO(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2008, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2002-2009, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <utime.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include <NodeMonitor.h>
|
#include <NodeMonitor.h>
|
||||||
|
|
||||||
#include <utime.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -27,10 +29,14 @@ utime(const char *path, const struct utimbuf *times)
|
|||||||
status_t status;
|
status_t status;
|
||||||
|
|
||||||
if (times != NULL) {
|
if (times != NULL) {
|
||||||
stat.st_atime = times->actime;
|
stat.st_atim.tv_sec = times->actime;
|
||||||
stat.st_mtime = times->modtime;
|
stat.st_mtim.tv_sec = times->modtime;
|
||||||
} else
|
stat.st_atim.tv_nsec = stat.st_mtim.tv_nsec = 0;
|
||||||
stat.st_atime = stat.st_mtime = time(NULL);
|
} else {
|
||||||
|
bigtime_t now = real_time_clock_usecs();
|
||||||
|
stat.st_atim.tv_sec = stat.st_mtim.tv_sec = now / 1000000;
|
||||||
|
stat.st_atim.tv_nsec = stat.st_mtim.tv_nsec = (now % 1000000) * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat),
|
status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat),
|
||||||
B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME);
|
B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME);
|
||||||
|
|||||||
Reference in New Issue
Block a user