xref: /plan9-contrib/sys/src/ape/lib/ap/plan9/utime.c (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
1 #include "lib.h"
2 #include <sys/types.h>
3 #include <time.h>
4 #include <utime.h>
5 #include <errno.h>
6 #include "sys9.h"
7 #include "dir.h"
8 
9 int
10 utime(const char *path, const struct utimbuf *times)
11 {
12 	int n;
13 	char cd[DIRLEN];
14 	Dir dir;
15 	time_t curt;
16 
17 	if(_STAT(path, cd) < 0){
18 		_syserrno();
19 		return -1;
20 	}
21 	convM2D(cd, &dir);
22 	if(times == 0) {
23 		curt = time(0);
24 		dir.atime = curt;
25 		dir.mtime = curt;
26 	} else {
27 		dir.atime = times->actime;
28 		dir.mtime = times->modtime;
29 	}
30 	convD2M(&dir, cd);
31 	n = _WSTAT(path, cd);
32 	if(n < 0)
33 		_syserrno();
34 	return n;
35 }
36