[libc-commits] [libc] [libc] Add support for SYS_fchmodat2 in fchmodat (PR #223997)

Aman Maurya via libc-commits libc-commits at lists.llvm.org
Thu Sep 17 01:07:27 PDT 2026


================
@@ -24,11 +25,25 @@
 namespace LIBC_NAMESPACE_DECL {
 namespace linux_syscalls {
 
-LIBC_INLINE ErrorOr<int> fchmodat(int fd, const char *path, mode_t mode) {
-  int ret = syscall_impl<int>(SYS_fchmodat, fd, path, mode);
-  if (ret < 0)
-    return Error(-ret);
+LIBC_INLINE ErrorOr<int> fchmodat(int fd, const char *path, mode_t mode,
+                                  int flags) {
+#if defined(SYS_fchmodat2)
+  auto ret = syscall_checked<int>(SYS_fchmodat2, fd, path, mode, flags);
+#if defined(SYS_fchmodat)
+  if (!ret && ret.error() == ENOSYS) {
+    if (flags != 0)
+      return Error(ENOTSUP);
+    return syscall_checked<int>(SYS_fchmodat, fd, path, mode);
+  }
+#endif
   return ret;
+#elif defined(SYS_fchmodat)
+  if (flags != 0)
+    return Error(ENOTSUP);
+  return syscall_checked<int>(SYS_fchmodat, fd, path, mode);
+#else
+#error "fchmodat2 and fchmodat syscalls not available."
+#endif
----------------
amanmaurya92 wrote:

I applied your suggestion, thanks! It cleans up the duplication nicely.

https://github.com/llvm/llvm-project/pull/223997


More information about the libc-commits mailing list