7 #define IS32BIT(x) !((x)+0x80000000ULL>>32)
8 #define NS_SPECIAL(ns) ((ns)==UTIME_NOW || (ns)==UTIME_OMIT)
10 int utimensat(int fd, const char *path, const struct timespec times[2], int flags)
13 if (times && times[0].tv_nsec==UTIME_NOW && times[1].tv_nsec==UTIME_NOW)
15 #ifdef SYS_utimensat_time64
20 ns0 = times[0].tv_nsec;
21 ns1 = times[1].tv_nsec;
22 if (!NS_SPECIAL(ns0)) s0 = times[0].tv_sec;
23 if (!NS_SPECIAL(ns1)) s1 = times[1].tv_sec;
25 if (SYS_utimensat == SYS_utimensat_time64 || !IS32BIT(s0) || !IS32BIT(s1))
26 r = __syscall(SYS_utimensat_time64, fd, path, times ?
27 ((long long[]){s0, ns0, s1, ns1}) : 0, flags);
28 if (SYS_utimensat == SYS_utimensat_time64 || r!=-ENOSYS)
29 return __syscall_ret(r);
30 if (!IS32BIT(s0) || !IS32BIT(s1))
31 return __syscall_ret(-ENOTSUP);
32 r = __syscall(SYS_utimensat, fd, path,
33 times ? ((long[]){s0, ns0, s1, ns1}) : 0, flags);
35 r = __syscall(SYS_utimensat, fd, path, times, flags);
39 if (r != -ENOSYS || flags) return __syscall_ret(r);
45 if (times[i].tv_nsec >= 1000000000ULL) {
46 if (NS_SPECIAL(times[i].tv_nsec))
47 return __syscall_ret(-ENOSYS);
48 return __syscall_ret(-EINVAL);
50 tmp[2*i+0] = times[i].tv_sec;
51 tmp[2*i+1] = times[i].tv_nsec / 1000;
55 r = __syscall(SYS_futimesat, fd, path, tv);
56 if (r != -ENOSYS || fd != AT_FDCWD) return __syscall_ret(r);
57 r = __syscall(SYS_utimes, path, tv);
59 return __syscall_ret(r);