Skip to content

Commit 5376c0d

Browse files
[libc] Enable utimes function for riscv
RV32 uses SYS_utimensat_time64 instead of SYS_utimensat but the call is the same.
1 parent 7548cec commit 5376c0d

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ set(TARGET_LIBC_ENTRYPOINTS
290290
libc.src.sys.statvfs.statvfs
291291

292292
# sys/utimes.h entrypoints
293-
# libc.src.sys.time.utimes
293+
libc.src.sys.time.utimes
294294

295295
# sys/utsname.h entrypoints
296296
libc.src.sys.utsname.uname

libc/include/sys/syscall.h.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,10 @@
23012301
#define SYS_utimes __NR_utimes
23022302
#endif
23032303

2304+
#ifdef __NR_utimensat_time64
2305+
#define SYS_utimensat_time64 __NR_utimensat_time64
2306+
#endif
2307+
23042308
#ifdef __NR_utrap_install
23052309
#define SYS_utrap_install __NR_utrap_install
23062310
#endif

libc/src/sys/time/linux/utimes.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "hdr/fcntl_macros.h"
1212
#include "hdr/types/struct_timeval.h"
13+
#include "hdr/types/struct_timespec.h"
1314

1415
#include "src/__support/OSUtil/syscall.h"
1516
#include "src/__support/common.h"
@@ -20,14 +21,24 @@
2021

2122
namespace LIBC_NAMESPACE_DECL {
2223

24+
#if 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+
2334
LLVM_LIBC_FUNCTION(int, utimes,
2435
(const char *path, const struct timeval times[2])) {
2536
int ret;
2637

2738
#ifdef SYS_utimes
2839
// 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)
3142
// the utimensat syscall requires a timespec struct, not timeval.
3243
struct timespec ts[2];
3344
struct timespec *ts_ptr = nullptr; // default value if times is nullptr
@@ -59,11 +70,8 @@ LLVM_LIBC_FUNCTION(int, utimes,
5970

6071
// utimensat syscall.
6172
// 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);
6775
#endif // SYS_utimensat
6876

6977
if (ret < 0) {

0 commit comments

Comments
 (0)