|
9 | 9 | #include "src/sys/time/utimes.h" |
10 | 10 |
|
11 | 11 | #include "hdr/fcntl_macros.h" |
| 12 | +#include "hdr/types/struct_timespec.h" |
12 | 13 | #include "hdr/types/struct_timeval.h" |
13 | 14 |
|
14 | 15 | #include "src/__support/OSUtil/syscall.h" |
|
20 | 21 |
|
21 | 22 | namespace LIBC_NAMESPACE_DECL { |
22 | 23 |
|
| 24 | +#ifdef SYS_utimes |
| 25 | +constexpr auto UTIMES_SYSCALL_ID = SYS_utimes; |
| 26 | +#elif defined(SYS_utimensat) |
| 27 | +constexpr auto UTIMES_SYSCALL_ID = SYS_utimensat; |
| 28 | +#elif defined(SYS_utimensat_time64) |
| 29 | +constexpr auto UTIMES_SYSCALL_ID = SYS_utimensat_time64; |
| 30 | +#else |
| 31 | +#error "utimes, utimensat, utimensat_time64, syscalls not available." |
| 32 | +#endif |
| 33 | + |
23 | 34 | LLVM_LIBC_FUNCTION(int, utimes, |
24 | 35 | (const char *path, const struct timeval times[2])) { |
25 | 36 | int ret; |
26 | 37 |
|
27 | 38 | #ifdef SYS_utimes |
28 | 39 | // No need to define a timespec struct, use the syscall directly. |
29 | | - ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_utimes, path, times); |
30 | | -#elif defined(SYS_utimensat) |
| 40 | + ret = LIBC_NAMESPACE::syscall_impl<int>(UTIMES_SYSCALL_ID, path, times); |
| 41 | +#elif defined(SYS_utimensat) || defined(SYS_utimensat_time64) |
31 | 42 | // the utimensat syscall requires a timespec struct, not timeval. |
32 | 43 | struct timespec ts[2]; |
33 | 44 | struct timespec *ts_ptr = nullptr; // default value if times is nullptr |
@@ -59,11 +70,8 @@ LLVM_LIBC_FUNCTION(int, utimes, |
59 | 70 |
|
60 | 71 | // utimensat syscall. |
61 | 72 | // flags=0 means don't follow symlinks (like utimes) |
62 | | - ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_utimensat, AT_FDCWD, path, ts_ptr, |
63 | | - 0); |
64 | | - |
65 | | -#else |
66 | | -#error "utimensat and utimes syscalls not available." |
| 73 | + ret = LIBC_NAMESPACE::syscall_impl<int>(UTIMES_SYSCALL_ID, AT_FDCWD, path, |
| 74 | + ts_ptr, 0); |
67 | 75 | #endif // SYS_utimensat |
68 | 76 |
|
69 | 77 | if (ret < 0) { |
|
0 commit comments