15af32e75SAxel 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. 45af32e75SAxel Dörfler */ 55af32e75SAxel Dörfler 65af32e75SAxel Dörfler 76a9eee58SAxel Dörfler #include <utime.h> 86a9eee58SAxel Dörfler 96a9eee58SAxel Dörfler #include <errno.h> 106a9eee58SAxel Dörfler #include <time.h> 116a9eee58SAxel Dörfler 125e2ef462SAxel Dörfler #include <NodeMonitor.h> 135af32e75SAxel Dörfler 14ae901935SOliver Tappe #include <errno_private.h> 155af32e75SAxel Dörfler #include <syscalls.h> 164d5c5a7eSAugustin Cavalier #include <syscall_utils.h> 175af32e75SAxel Dörfler 185af32e75SAxel Dörfler 195af32e75SAxel Dörfler int utime(const char * path,const struct utimbuf * times)205af32e75SAxel Dörflerutime(const char *path, const struct utimbuf *times) 215af32e75SAxel Dörfler { 225af32e75SAxel Dörfler struct stat stat; 235af32e75SAxel Dörfler status_t status; 245af32e75SAxel Dörfler 255af32e75SAxel 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 } 345af32e75SAxel Dörfler 35*55e8238cSAugustin Cavalier status = _kern_write_stat(AT_FDCWD, path, true, &stat, sizeof(struct stat), 365e2ef462SAxel Dörfler B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME); 375af32e75SAxel Dörfler 385af32e75SAxel Dörfler RETURN_AND_SET_ERRNO(status); 395af32e75SAxel Dörfler } 405af32e75SAxel Dörfler 41