Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 36b4ffe

Browse filesBrowse files
[libc] Enable utimes function for riscv (#139181)
RV32 uses SYS_utimensat_time64 instead of SYS_utimensat but the call is the same.
1 parent 66bb445 commit 36b4ffe
Copy full SHA for 36b4ffe

File tree

Expand file treeCollapse file tree

3 files changed

+20
-8
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+20
-8
lines changed

‎libc/config/linux/riscv/entrypoints.txt

Copy file name to clipboardExpand all lines: libc/config/linux/riscv/entrypoints.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ set(TARGET_LIBC_ENTRYPOINTS
289289
libc.src.sys.statvfs.statvfs
290290

291291
# sys/utimes.h entrypoints
292-
# libc.src.sys.time.utimes
292+
libc.src.sys.time.utimes
293293

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

‎libc/include/sys/syscall.h.def

Copy file name to clipboardExpand all lines: libc/include/sys/syscall.h.def
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,6 +2305,10 @@
23052305
#define SYS_utimes __NR_utimes
23062306
#endif
23072307

2308+
#ifdef __NR_utimensat_time64
2309+
#define SYS_utimensat_time64 __NR_utimensat_time64
2310+
#endif
2311+
23082312
#ifdef __NR_utrap_install
23092313
#define SYS_utrap_install __NR_utrap_install
23102314
#endif

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

Copy file name to clipboardExpand all lines: libc/src/sys/time/linux/utimes.cpp
+15-7Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "src/sys/time/utimes.h"
1010

1111
#include "hdr/fcntl_macros.h"
12+
#include "hdr/types/struct_timespec.h"
1213
#include "hdr/types/struct_timeval.h"
1314

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

2122
namespace LIBC_NAMESPACE_DECL {
2223

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+
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.