[libc-commits] [libc] c765566 - [libc] Add support for chown on platforms that don't define SYS_chown (#186167)
via libc-commits
libc-commits at lists.llvm.org
Fri Mar 13 07:04:43 PDT 2026
Author: Mikhail R. Gadelha
Date: 2026-03-13T11:04:37-03:00
New Revision: c7655664a2421816a5daa1704c4c729c28db76e3
URL: https://github.com/llvm/llvm-project/commit/c7655664a2421816a5daa1704c4c729c28db76e3
DIFF: https://github.com/llvm/llvm-project/commit/c7655664a2421816a5daa1704c4c729c28db76e3.diff
LOG: [libc] Add support for chown on platforms that don't define SYS_chown (#186167)
Some platforms don't define SYS_chown (like risc-v), so this PR adds a
fallback to calling SYS_fchownat.
Added:
Modified:
libc/config/linux/riscv/entrypoints.txt
libc/src/unistd/linux/CMakeLists.txt
libc/src/unistd/linux/chown.cpp
Removed:
################################################################################
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 38b441551316a..36f13a3bf156b 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -324,6 +324,7 @@ set(TARGET_LIBC_ENTRYPOINTS
# unistd.h entrypoints
libc.src.unistd.access
libc.src.unistd.chdir
+ libc.src.unistd.chown
libc.src.unistd.close
libc.src.unistd.dup
libc.src.unistd.dup2
diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index 560c78552fec8..9e530b634e566 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -32,6 +32,7 @@ add_entrypoint_object(
HDRS
../chown.h
DEPENDS
+ libc.hdr.fcntl_macros
libc.hdr.types.uid_t
libc.hdr.types.gid_t
libc.include.sys_syscall
diff --git a/libc/src/unistd/linux/chown.cpp b/libc/src/unistd/linux/chown.cpp
index c7bf1703ffe57..1e7817a1e91a9 100644
--- a/libc/src/unistd/linux/chown.cpp
+++ b/libc/src/unistd/linux/chown.cpp
@@ -11,6 +11,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
+#include "hdr/fcntl_macros.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include <sys/syscall.h> // For syscall numbers.
@@ -18,7 +19,15 @@
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, chown, (const char *path, uid_t owner, gid_t group)) {
+#ifdef SYS_chown
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_chown, path, owner, group);
+#elif defined(SYS_fchownat)
+ int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_fchownat, AT_FDCWD, path,
+ owner, group, 0);
+#else
+#error "chown and fchownat syscalls not available."
+#endif
+
if (ret < 0) {
libc_errno = -ret;
return -1;
More information about the libc-commits
mailing list