[libc-commits] [libc] 230f332 - [libc] Swap order of syscall on chmod (#138427)

via libc-commits libc-commits at lists.llvm.org
Mon May 5 14:49:37 PDT 2025


Author: Mikhail R. Gadelha
Date: 2025-05-05T18:49:33-03:00
New Revision: 230f332cf0139fed88145c9d2dd410c36348f2e4

URL: https://github.com/llvm/llvm-project/commit/230f332cf0139fed88145c9d2dd410c36348f2e4
DIFF: https://github.com/llvm/llvm-project/commit/230f332cf0139fed88145c9d2dd410c36348f2e4.diff

LOG: [libc] Swap order of syscall on chmod (#138427)

We define SYS_fchmodat2 on libc but the syscall is not available on old
kernels, so prefer the SYS_fchmodat version when possible.

Added: 
    

Modified: 
    libc/src/sys/stat/linux/chmod.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/sys/stat/linux/chmod.cpp b/libc/src/sys/stat/linux/chmod.cpp
index 57d5bae6b8191..1b787e47e7c68 100644
--- a/libc/src/sys/stat/linux/chmod.cpp
+++ b/libc/src/sys/stat/linux/chmod.cpp
@@ -23,12 +23,12 @@ namespace LIBC_NAMESPACE_DECL {
 LLVM_LIBC_FUNCTION(int, chmod, (const char *path, mode_t mode)) {
 #ifdef SYS_chmod
   int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_chmod, path, mode);
-#elif defined(SYS_fchmodat2)
-  int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_fchmodat2, AT_FDCWD, path,
-                                              mode, 0, AT_SYMLINK_NOFOLLOW);
 #elif defined(SYS_fchmodat)
   int ret =
       LIBC_NAMESPACE::syscall_impl<int>(SYS_fchmodat, AT_FDCWD, path, mode, 0);
+#elif defined(SYS_fchmodat2)
+  int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_fchmodat2, AT_FDCWD, path,
+                                              mode, 0, AT_SYMLINK_NOFOLLOW);
 #else
 #error "chmod, fchmodat and fchmodat2 syscalls not available."
 #endif


        


More information about the libc-commits mailing list