15e2ef462SAxel Dörfler/*
26a9eee58SAxel Dörfler * Copyright 2002-2009, Axel D��rfler, axeld@pinc-software.de.
35e2ef462SAxel Dörfler * Distributed under the terms of the MIT License.
45e2ef462SAxel Dörfler */
50dd93a6eSAxel Dörfler
60dd93a6eSAxel Dörfler
70dd93a6eSAxel Dörfler#include <utime.h>
86a9eee58SAxel Dörfler
90dd93a6eSAxel Dörfler#include <errno.h>
106a9eee58SAxel Dörfler#include <time.h>
116a9eee58SAxel Dörfler
126a9eee58SAxel Dörfler#include <NodeMonitor.h>
136a9eee58SAxel Dörfler
14ae901935SOliver Tappe#include <errno_private.h>
150dd93a6eSAxel Dörfler#include <syscalls.h>
164d5c5a7eSAugustin Cavalier#include <syscall_utils.h>
170dd93a6eSAxel Dörfler
180dd93a6eSAxel Dörfler
190dd93a6eSAxel Dörflerint
2090b31eb3SAxel Dörflerutime(const char *path, const struct utimbuf *times)
210dd93a6eSAxel Dörfler{
220dd93a6eSAxel Dörfler	struct stat stat;
230dd93a6eSAxel Dörfler	status_t status;
240dd93a6eSAxel Dörfler
2590b31eb3SAxel Dörfler	if (times != NULL) {
266a9eee58SAxel Dörfler		stat.st_atim.tv_sec = times->actime;
276a9eee58SAxel Dörfler		stat.st_mtim.tv_sec = times->modtime;
286a9eee58SAxel Dörfler		stat.st_atim.tv_nsec = stat.st_mtim.tv_nsec = 0;
296a9eee58SAxel Dörfler	} else {
306a9eee58SAxel Dörfler		bigtime_t now = real_time_clock_usecs();
316a9eee58SAxel Dörfler		stat.st_atim.tv_sec = stat.st_mtim.tv_sec = now / 1000000;
326a9eee58SAxel Dörfler		stat.st_atim.tv_nsec = stat.st_mtim.tv_nsec = (now % 1000000) * 1000;
336a9eee58SAxel Dörfler	}
3490b31eb3SAxel Dörfler
35383cdedbSIngo Weinhold	status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat),
365e2ef462SAxel Dörfler		B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME);
370dd93a6eSAxel Dörfler
380dd93a6eSAxel Dörfler	RETURN_AND_SET_ERRNO(status);
390dd93a6eSAxel Dörfler}
400dd93a6eSAxel Dörfler
41