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