[libc] Enable utimes function for riscv (#139181)

RV32 uses SYS_utimensat_time64 instead of SYS_utimensat but the call is
the same.
This commit is contained in:
Mikhail R. Gadelha
2025-05-13 18:59:49 -03:00
committed by GitHub
parent 66bb445d5c
commit 36b4ffeb7e
3 changed files with 20 additions and 8 deletions

View File

@@ -289,7 +289,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sys.statvfs.statvfs
# sys/utimes.h entrypoints
# libc.src.sys.time.utimes
libc.src.sys.time.utimes
# sys/utsname.h entrypoints
libc.src.sys.utsname.uname

View File

@@ -2305,6 +2305,10 @@
#define SYS_utimes __NR_utimes
#endif
#ifdef __NR_utimensat_time64
#define SYS_utimensat_time64 __NR_utimensat_time64
#endif
#ifdef __NR_utrap_install
#define SYS_utrap_install __NR_utrap_install
#endif

View File

@@ -9,6 +9,7 @@
#include "src/sys/time/utimes.h"
#include "hdr/fcntl_macros.h"
#include "hdr/types/struct_timespec.h"
#include "hdr/types/struct_timeval.h"
#include "src/__support/OSUtil/syscall.h"
@@ -20,14 +21,24 @@
namespace LIBC_NAMESPACE_DECL {
#ifdef SYS_utimes
constexpr auto UTIMES_SYSCALL_ID = SYS_utimes;
#elif defined(SYS_utimensat)
constexpr auto UTIMES_SYSCALL_ID = SYS_utimensat;
#elif defined(SYS_utimensat_time64)
constexpr auto UTIMES_SYSCALL_ID = SYS_utimensat_time64;
#else
#error "utimes, utimensat, utimensat_time64, syscalls not available."
#endif
LLVM_LIBC_FUNCTION(int, utimes,
(const char *path, const struct timeval times[2])) {
int ret;
#ifdef SYS_utimes
// No need to define a timespec struct, use the syscall directly.
ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_utimes, path, times);
#elif defined(SYS_utimensat)
ret = LIBC_NAMESPACE::syscall_impl<int>(UTIMES_SYSCALL_ID, path, times);
#elif defined(SYS_utimensat) || defined(SYS_utimensat_time64)
// the utimensat syscall requires a timespec struct, not timeval.
struct timespec ts[2];
struct timespec *ts_ptr = nullptr; // default value if times is nullptr
@@ -59,11 +70,8 @@ LLVM_LIBC_FUNCTION(int, utimes,
// utimensat syscall.
// flags=0 means don't follow symlinks (like utimes)
ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_utimensat, AT_FDCWD, path, ts_ptr,
0);
#else
#error "utimensat and utimes syscalls not available."
ret = LIBC_NAMESPACE::syscall_impl<int>(UTIMES_SYSCALL_ID, AT_FDCWD, path,
ts_ptr, 0);
#endif // SYS_utimensat
if (ret < 0) {