Skip to content

[libc] Swap order of syscall on chmod #138427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mikhailramalho
Copy link
Member

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

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

llvmbot commented May 3, 2025

@llvm/pr-subscribers-libc

Author: Mikhail R. Gadelha (mikhailramalho)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/138427.diff

1 Files Affected:

  • (modified) libc/src/sys/stat/linux/chmod.cpp (+3-3)
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants