[libc-commits] [libc] [libc] prefer *at syscalls in sys/stat wrappers (PR #195792)
Kiriti Ponduri via libc-commits
libc-commits at lists.llvm.org
Tue May 5 02:36:30 PDT 2026
https://github.com/udaykiriti updated https://github.com/llvm/llvm-project/pull/195792
>From 5529e876a423002b5e65867992957c775a8bc81d Mon Sep 17 00:00:00 2001
From: udaykiriti <udaykiriti624 at gmail.com>
Date: Tue, 5 May 2026 10:15:43 +0530
Subject: [PATCH] [libc] prefer *at syscalls in sys/stat wrappers
- so the changes flips the #ifdef order to prefer the *at syscalls over normal ones.
- In modern architectures, *at system calls are preferred over normal
system calls.
- so by checking for "*at" sys calls first, we ensure better
compatibility with modern systems.
- then normal syscalls moved to else for support of older ones.
Signed-off-by: udaykiriti <udaykiriti624 at gmail.com>
---
libc/src/__support/OSUtil/linux/syscall_wrappers/chmod.h | 6 +++---
libc/src/__support/OSUtil/linux/syscall_wrappers/mkdir.h | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/chmod.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/chmod.h
index 69acf4c5cf1b3..42b0d3db98326 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/chmod.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/chmod.h
@@ -26,13 +26,13 @@ namespace LIBC_NAMESPACE_DECL {
namespace linux_syscalls {
LIBC_INLINE ErrorOr<int> chmod(const char *path, mode_t mode) {
-#ifdef SYS_chmod
- int ret = syscall_impl<int>(SYS_chmod, path, mode);
-#elif defined(SYS_fchmodat)
+#ifdef SYS_fchmodat
int ret = syscall_impl<int>(SYS_fchmodat, AT_FDCWD, path, mode, 0);
#elif defined(SYS_fchmodat2)
int ret = syscall_impl<int>(SYS_fchmodat2, AT_FDCWD, path, mode, 0,
AT_SYMLINK_NOFOLLOW);
+#elif defined(SYS_chmod)
+ int ret = syscall_impl<int>(SYS_chmod, path, mode);
#else
#error "chmod, fchmodat and fchmodat2 syscalls not available."
#endif
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/mkdir.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/mkdir.h
index 6d77894c36b6b..b5002914c5ec0 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/mkdir.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/mkdir.h
@@ -26,10 +26,10 @@ namespace LIBC_NAMESPACE_DECL {
namespace linux_syscalls {
LIBC_INLINE ErrorOr<int> mkdir(const char *path, mode_t mode) {
-#ifdef SYS_mkdir
- int ret = syscall_impl<int>(SYS_mkdir, path, mode);
-#else
+#ifdef SYS_mkdirat
int ret = syscall_impl<int>(SYS_mkdirat, AT_FDCWD, path, mode);
+#else
+ int ret = syscall_impl<int>(SYS_mkdir, path, mode);
#endif
if (ret < 0)
return Error(-ret);
More information about the libc-commits
mailing list