* 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:
Axel Dörfler 2009-08-29 15:53:15 +00:00
parent d18b04298a
commit 6a9eee5845
2 changed files with 46 additions and 18 deletions

View File

@ -1,25 +1,47 @@
/*
* Copyright 2006, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2006-2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#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
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) {
timeBuffer = &buffer;
buffer.actime = times[0].tv_sec + times[0].tv_usec / 1000000LL;
buffer.modtime = times[1].tv_sec + times[1].tv_usec / 1000000LL;
} else
timeBuffer = NULL;
stat.st_atim.tv_sec = times[0].tv_sec;
stat.st_atim.tv_nsec = times[0].tv_usec * 1000;
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);
}

View File

@ -1,14 +1,16 @@
/*
* Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#include <utime.h>
#include <errno.h>
#include <time.h>
#include <NodeMonitor.h>
#include <utime.h>
#include <time.h>
#include <errno.h>
#include <syscalls.h>
@ -27,10 +29,14 @@ utime(const char *path, const struct utimbuf *times)
status_t status;
if (times != NULL) {
stat.st_atime = times->actime;
stat.st_mtime = times->modtime;
} else
stat.st_atime = stat.st_mtime = time(NULL);
stat.st_atim.tv_sec = times->actime;
stat.st_mtim.tv_sec = times->modtime;
stat.st_atim.tv_nsec = stat.st_mtim.tv_nsec = 0;
} 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);