1 /* 2 ** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 ** Distributed under the terms of the Haiku License. 4 */ 5 6 7 #include <fs_interface.h> 8 9 #include <utime.h> 10 #include <time.h> 11 #include <errno.h> 12 #include <syscalls.h> 13 14 15 #define RETURN_AND_SET_ERRNO(err) \ 16 if (err < 0) { \ 17 errno = err; \ 18 return -1; \ 19 } \ 20 return err; 21 22 23 int 24 utime(const char *path, const struct utimbuf *times) 25 { 26 struct stat stat; 27 status_t status; 28 29 if (times != NULL) { 30 stat.st_atime = times->actime; 31 stat.st_mtime = times->modtime; 32 } else 33 stat.st_atime = stat.st_mtime = time(NULL); 34 35 status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat), 36 FS_WRITE_STAT_MTIME | FS_WRITE_STAT_ATIME); 37 38 RETURN_AND_SET_ERRNO(status); 39 } 40 41