1 #include <sys/stat.h>
2 #include <sys/time.h>
3 #include <fcntl.h>
4 #include <errno.h>
5 #include "syscall.h"
6
utimensat(int fd,const char * path,const struct timespec times[2],int flags)7 int utimensat(int fd, const char *path, const struct timespec times[2], int flags)
8 {
9 int r = __syscall(SYS_utimensat, fd, path, times, flags);
10 #ifdef SYS_futimesat
11 if (r != -ENOSYS || flags) return __syscall_ret(r);
12 struct timeval *tv = 0, tmp[2];
13 if (times) {
14 int i;
15 tv = tmp;
16 for (i=0; i<2; i++) {
17 if (times[i].tv_nsec >= 1000000000ULL) {
18 if (times[i].tv_nsec == UTIME_NOW &&
19 times[1-i].tv_nsec == UTIME_NOW) {
20 tv = 0;
21 break;
22 }
23 if (times[i].tv_nsec == UTIME_OMIT)
24 return __syscall_ret(-ENOSYS);
25 return __syscall_ret(-EINVAL);
26 }
27 tmp[i].tv_sec = times[i].tv_sec;
28 tmp[i].tv_usec = times[i].tv_nsec / 1000;
29 }
30 }
31
32 r = __syscall(SYS_futimesat, fd, path, tv);
33 if (r != -ENOSYS || fd != AT_FDCWD) return __syscall_ret(r);
34 r = __syscall(SYS_utimes, path, tv);
35 #endif
36 return __syscall_ret(r);
37 }
38