[libc-commits] [libc] [llvm] [libc] Move fcntl implementation into the syscall_wrappers layer (PR #207878)

Mikhail R. Gadelha via libc-commits libc-commits at lists.llvm.org
Tue Jul 7 08:14:43 PDT 2026


https://github.com/mikhailramalho updated https://github.com/llvm/llvm-project/pull/207878

>From 9e894325ed5e937f0eb22f2cb00739160493d7f9 Mon Sep 17 00:00:00 2001
From: "Mikhail R. Gadelha" <mikhail at igalia.com>
Date: Mon, 6 Jul 2026 21:55:14 -0300
Subject: [PATCH 1/2] [libc] Move fcntl implementation into the
 syscall_wrappers layer

linux_syscalls::fcntl called SYS_fcntl unconditionally, breaking the
riscv32 full build where only SYS_fcntl64 exists. The syscall selection
and command translation already lived in internal::fcntl, so move that
implementation into syscall_wrappers/fcntl.h, delete the legacy
OSUtil/fcntl.h and OSUtil/linux/fcntl.cpp, and port the callers (fcntl
entrypoint, file.cpp, dup2.h) to linux_syscalls::fcntl.
---
 libc/config/linux/riscv/entrypoints.txt       |  11 +-
 libc/src/__support/File/linux/CMakeLists.txt  |   3 +-
 libc/src/__support/File/linux/file.cpp        |   6 +-
 libc/src/__support/OSUtil/fcntl.h             |  27 ----
 .../src/__support/OSUtil/linux/CMakeLists.txt |   7 -
 libc/src/__support/OSUtil/linux/fcntl.cpp     | 120 ------------------
 .../linux/syscall_wrappers/CMakeLists.txt     |   7 +
 .../OSUtil/linux/syscall_wrappers/dup2.h      |  15 +--
 .../OSUtil/linux/syscall_wrappers/fcntl.h     |  97 ++++++++++++--
 libc/src/fcntl/linux/CMakeLists.txt           |   1 +
 libc/src/fcntl/linux/fcntl.cpp                |   4 +-
 .../llvm-project-overlay/libc/BUILD.bazel     |  11 +-
 12 files changed, 119 insertions(+), 190 deletions(-)
 delete mode 100644 libc/src/__support/OSUtil/fcntl.h
 delete mode 100644 libc/src/__support/OSUtil/linux/fcntl.cpp

diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index bef3bca77df0e..a7506ddbc2705 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1151,12 +1151,11 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.compiler.__stack_chk_fail
 
     # dirent.h entrypoints
-    # SYS_fcntl isn't available on RISC-V 32 QEMU.
-    # libc.src.dirent.closedir
-    # libc.src.dirent.dirfd
-    # libc.src.dirent.opendir
-    # libc.src.dirent.readdir
-    # libc.src.dirent.fdopendir
+    libc.src.dirent.closedir
+    libc.src.dirent.dirfd
+    libc.src.dirent.opendir
+    libc.src.dirent.readdir
+    libc.src.dirent.fdopendir
 
     # arpa/inet.h entrypoints
     libc.src.arpa.inet.htonl
diff --git a/libc/src/__support/File/linux/CMakeLists.txt b/libc/src/__support/File/linux/CMakeLists.txt
index ba64ecf41a76e..76ba4bd062446 100644
--- a/libc/src/__support/File/linux/CMakeLists.txt
+++ b/libc/src/__support/File/linux/CMakeLists.txt
@@ -13,6 +13,7 @@ add_object_library(
     libc.include.sys_stat
     libc.src.__support.CPP.new
     libc.src.__support.OSUtil.osutil
+    libc.src.__support.OSUtil.linux.syscall_wrappers.fcntl
     libc.src.__support.OSUtil.linux.syscall_wrappers.lseek
     libc.src.__support.OSUtil.linux.syscall_wrappers.open
     libc.src.__support.error_or
@@ -32,8 +33,8 @@ add_object_library(
     libc.src.__support.OSUtil.linux.stat.kernel_statx_types
     libc.src.__support.OSUtil.osutil
     libc.src.__support.OSUtil.linux.syscall_wrappers.open
-    libc.src.__support.OSUtil.linux.syscall_wrappers.statx
     libc.src.__support.OSUtil.linux.syscall_wrappers.fcntl
+    libc.src.__support.OSUtil.linux.syscall_wrappers.statx
     libc.src.__support.error_or
     libc.src.errno.errno
     libc.src.__support.File.dir
diff --git a/libc/src/__support/File/linux/file.cpp b/libc/src/__support/File/linux/file.cpp
index e89b3d118deb1..c526f2dd01411 100644
--- a/libc/src/__support/File/linux/file.cpp
+++ b/libc/src/__support/File/linux/file.cpp
@@ -12,7 +12,7 @@
 #include "hdr/types/off_t.h"
 #include "src/__support/CPP/new.h"
 #include "src/__support/File/file.h"
-#include "src/__support/OSUtil/fcntl.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/fcntl.h"
 #include "src/__support/OSUtil/linux/syscall_wrappers/lseek.h"
 #include "src/__support/OSUtil/linux/syscall_wrappers/open.h"
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
@@ -120,7 +120,7 @@ ErrorOr<LinuxFile *> create_file_from_fd(int fd, const char *mode) {
     return Error(EINVAL);
   }
 
-  auto result = internal::fcntl(fd, F_GETFL);
+  auto result = linux_syscalls::fcntl(fd, F_GETFL);
   if (!result.has_value()) {
     return Error(EBADF);
   }
@@ -138,7 +138,7 @@ ErrorOr<LinuxFile *> create_file_from_fd(int fd, const char *mode) {
   if ((modeflags & static_cast<ModeFlags>(OpenMode::APPEND)) &&
       !(fd_flags & O_APPEND)) {
     do_seek = true;
-    if (!internal::fcntl(fd, F_SETFL,
+    if (!linux_syscalls::fcntl(fd, F_SETFL,
                          reinterpret_cast<void *>(fd_flags | O_APPEND))
              .has_value()) {
       return Error(EBADF);
diff --git a/libc/src/__support/OSUtil/fcntl.h b/libc/src/__support/OSUtil/fcntl.h
deleted file mode 100644
index 3983d78f7f89c..0000000000000
--- a/libc/src/__support/OSUtil/fcntl.h
+++ /dev/null
@@ -1,27 +0,0 @@
-//===-- Implementation header of internal fcntl function ------------------===//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FCNTL_H
-#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FCNTL_H
-
-#include "hdr/types/mode_t.h"
-#include "src/__support/error_or.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-namespace internal {
-
-ErrorOr<int> fcntl(int fd, int cmd, void *arg = nullptr);
-
-ErrorOr<int> open(const char *path, int flags, mode_t mode_flags = 0);
-
-ErrorOr<int> close(int fd);
-
-} // namespace internal
-} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FCNTL_H
diff --git a/libc/src/__support/OSUtil/linux/CMakeLists.txt b/libc/src/__support/OSUtil/linux/CMakeLists.txt
index 1f11067f0154f..ad8bbe658c1bb 100644
--- a/libc/src/__support/OSUtil/linux/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/CMakeLists.txt
@@ -10,7 +10,6 @@ add_object_library(
   linux_util
   SRCS
     exit.cpp
-    fcntl.cpp
   HDRS
     io.h
     syscall.h
@@ -18,12 +17,6 @@ add_object_library(
     .${LIBC_TARGET_ARCHITECTURE}.linux_${LIBC_TARGET_ARCHITECTURE}_util
     libc.src.__support.common
     libc.src.__support.CPP.string_view
-    libc.src.__support.error_or
-    libc.hdr.fcntl_macros
-    libc.hdr.types.struct_flock
-    libc.hdr.types.struct_flock64
-    libc.hdr.types.struct_f_owner_ex
-    libc.hdr.types.off_t
     libc.include.sys_syscall
 )
 
diff --git a/libc/src/__support/OSUtil/linux/fcntl.cpp b/libc/src/__support/OSUtil/linux/fcntl.cpp
deleted file mode 100644
index a31cb4ae3f600..0000000000000
--- a/libc/src/__support/OSUtil/linux/fcntl.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-//===-- Implementation of internal fcntl ----------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "src/__support/OSUtil/fcntl.h"
-
-#include "hdr/errno_macros.h"
-#include "hdr/fcntl_macros.h"
-#include "hdr/types/mode_t.h"
-#include "hdr/types/off_t.h"
-#include "hdr/types/struct_f_owner_ex.h"
-#include "hdr/types/struct_flock.h"
-#include "hdr/types/struct_flock64.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
-#include "src/__support/common.h"
-#include "src/__support/error_or.h"
-#include "src/__support/macros/config.h"
-
-#include <sys/syscall.h> // For syscall numbers.
-
-namespace LIBC_NAMESPACE_DECL {
-namespace internal {
-
-ErrorOr<int> fcntl(int fd, int cmd, void *arg) {
-#if SYS_fcntl
-  constexpr auto FCNTL_SYSCALL_ID = SYS_fcntl;
-#elif defined(SYS_fcntl64)
-  constexpr auto FCNTL_SYSCALL_ID = SYS_fcntl64;
-#else
-#error "fcntl and fcntl64 syscalls not available."
-#endif
-
-  switch (cmd) {
-  case F_OFD_SETLKW: {
-    struct flock *flk = reinterpret_cast<struct flock *>(arg);
-    // convert the struct to a flock64
-    struct flock64 flk64;
-    flk64.l_type = flk->l_type;
-    flk64.l_whence = flk->l_whence;
-    flk64.l_start = flk->l_start;
-    flk64.l_len = flk->l_len;
-    flk64.l_pid = flk->l_pid;
-    // create a syscall
-    int ret =
-        LIBC_NAMESPACE::syscall_impl<int>(FCNTL_SYSCALL_ID, fd, cmd, &flk64);
-    if (ret < 0)
-      return Error(-ret);
-    return ret;
-  }
-  case F_OFD_GETLK:
-  case F_OFD_SETLK: {
-    struct flock *flk = reinterpret_cast<struct flock *>(arg);
-    // convert the struct to a flock64
-    struct flock64 flk64;
-    flk64.l_type = flk->l_type;
-    flk64.l_whence = flk->l_whence;
-    flk64.l_start = flk->l_start;
-    flk64.l_len = flk->l_len;
-    flk64.l_pid = flk->l_pid;
-    // create a syscall
-    int ret =
-        LIBC_NAMESPACE::syscall_impl<int>(FCNTL_SYSCALL_ID, fd, cmd, &flk64);
-    // On failure, return
-    if (ret < 0)
-      return Error(-ret);
-    // Check for overflow, i.e. the offsets are not the same when cast
-    // to off_t from off64_t.
-    if (static_cast<off_t>(flk64.l_len) != flk64.l_len ||
-        static_cast<off_t>(flk64.l_start) != flk64.l_start)
-      return Error(EOVERFLOW);
-
-    // Now copy back into flk, in case flk64 got modified
-    flk->l_type = flk64.l_type;
-    flk->l_whence = flk64.l_whence;
-    flk->l_start = static_cast<decltype(flk->l_start)>(flk64.l_start);
-    flk->l_len = static_cast<decltype(flk->l_len)>(flk64.l_len);
-    flk->l_pid = flk64.l_pid;
-    return ret;
-  }
-  case F_GETOWN: {
-    struct f_owner_ex fex;
-    int ret = LIBC_NAMESPACE::syscall_impl<int>(FCNTL_SYSCALL_ID, fd,
-                                                F_GETOWN_EX, &fex);
-    if (ret < 0)
-      return Error(-ret);
-    return fex.type == F_OWNER_PGRP ? -fex.pid : fex.pid;
-  }
-#ifdef SYS_fcntl64
-  case F_GETLK: {
-    if constexpr (FCNTL_SYSCALL_ID == SYS_fcntl64)
-      cmd = F_GETLK64;
-    break;
-  }
-  case F_SETLK: {
-    if constexpr (FCNTL_SYSCALL_ID == SYS_fcntl64)
-      cmd = F_SETLK64;
-    break;
-  }
-  case F_SETLKW: {
-    if constexpr (FCNTL_SYSCALL_ID == SYS_fcntl64)
-      cmd = F_SETLKW64;
-    break;
-  }
-#endif
-  }
-
-  // default, but may use rewritten cmd from above.
-  int ret = LIBC_NAMESPACE::syscall_impl<int>(FCNTL_SYSCALL_ID, fd, cmd,
-                                              reinterpret_cast<void *>(arg));
-  if (ret < 0)
-    return Error(-ret);
-  return ret;
-}
-
-} // namespace internal
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 7f416bb5a2407..a3cdb17e9ea5c 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -640,6 +640,12 @@ add_header_library(
     libc.src.__support.common
     libc.src.__support.error_or
     libc.src.__support.macros.config
+    libc.hdr.errno_macros
+    libc.hdr.fcntl_macros
+    libc.hdr.types.off_t
+    libc.hdr.types.struct_f_owner_ex
+    libc.hdr.types.struct_flock
+    libc.hdr.types.struct_flock64
     libc.include.sys_syscall
 )
 
@@ -674,6 +680,7 @@ add_header_library(
     dup2.h
   DEPENDS
     libc.src.__support.OSUtil.osutil
+    libc.src.__support.OSUtil.linux.syscall_wrappers.fcntl
     libc.src.__support.common
     libc.src.__support.error_or
     libc.src.__support.macros.config
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/dup2.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/dup2.h
index 49f37134bd5f5..78da9801895ab 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/dup2.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/dup2.h
@@ -16,6 +16,7 @@
 
 #include "hdr/fcntl_macros.h"
 #include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall_wrappers/fcntl.h"
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -29,16 +30,10 @@ LIBC_INLINE ErrorOr<int> dup2(int oldfd, int newfd) {
   int ret = syscall_impl<int>(SYS_dup2, oldfd, newfd);
 #elif defined(SYS_dup3)
   if (oldfd == newfd) {
-#if defined(SYS_fcntl)
-    int ret = syscall_impl<int>(SYS_fcntl, oldfd, F_GETFD);
-#elif defined(SYS_fcntl64)
-    int ret = syscall_impl<int>(SYS_fcntl64, oldfd, F_GETFD);
-#else
-#error "SYS_fcntl and SYS_fcntl64 syscalls not available."
-#endif
-    if (ret >= 0)
-      return oldfd;
-    return Error(-ret);
+    auto ret = fcntl(oldfd, F_GETFD);
+    if (!ret)
+      return Error(ret.error());
+    return oldfd;
   }
   int ret = syscall_impl<int>(SYS_dup3, oldfd, newfd, 0);
 #else
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/fcntl.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/fcntl.h
index ce73fe71f18cb..0581693f9612c 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/fcntl.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/fcntl.h
@@ -14,6 +14,12 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FCNTL_H
 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FCNTL_H
 
+#include "hdr/errno_macros.h"
+#include "hdr/fcntl_macros.h"
+#include "hdr/types/off_t.h"
+#include "hdr/types/struct_f_owner_ex.h"
+#include "hdr/types/struct_flock.h"
+#include "hdr/types/struct_flock64.h"
 #include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
@@ -23,15 +29,90 @@
 namespace LIBC_NAMESPACE_DECL {
 namespace linux_syscalls {
 
-LIBC_INLINE ErrorOr<int> fcntl(int fd, int cmd, void *arg) {
-  int ret = syscall_impl<int>(SYS_fcntl, fd, cmd, arg);
-  if (ret < 0)
-    return Error(-ret);
-  return ret;
-}
+LIBC_INLINE ErrorOr<int> fcntl(int fd, int cmd, void *arg = nullptr) {
+#ifdef SYS_fcntl
+  constexpr auto FCNTL_SYSCALL_ID = SYS_fcntl;
+#elif defined(SYS_fcntl64)
+  constexpr auto FCNTL_SYSCALL_ID = SYS_fcntl64;
+#else
+#error "fcntl and fcntl64 syscalls not available."
+#endif
+
+  switch (cmd) {
+  case F_OFD_SETLKW: {
+    struct flock *flk = reinterpret_cast<struct flock *>(arg);
+    // convert the struct to a flock64
+    struct flock64 flk64;
+    flk64.l_type = flk->l_type;
+    flk64.l_whence = flk->l_whence;
+    flk64.l_start = flk->l_start;
+    flk64.l_len = flk->l_len;
+    flk64.l_pid = flk->l_pid;
+    // create a syscall
+    int ret = syscall_impl<int>(FCNTL_SYSCALL_ID, fd, cmd, &flk64);
+    if (ret < 0)
+      return Error(-ret);
+    return ret;
+  }
+  case F_OFD_GETLK:
+  case F_OFD_SETLK: {
+    struct flock *flk = reinterpret_cast<struct flock *>(arg);
+    // convert the struct to a flock64
+    struct flock64 flk64;
+    flk64.l_type = flk->l_type;
+    flk64.l_whence = flk->l_whence;
+    flk64.l_start = flk->l_start;
+    flk64.l_len = flk->l_len;
+    flk64.l_pid = flk->l_pid;
+    // create a syscall
+    int ret = syscall_impl<int>(FCNTL_SYSCALL_ID, fd, cmd, &flk64);
+    // On failure, return
+    if (ret < 0)
+      return Error(-ret);
+    // Check for overflow, i.e. the offsets are not the same when cast
+    // to off_t from off64_t.
+    if (static_cast<off_t>(flk64.l_len) != flk64.l_len ||
+        static_cast<off_t>(flk64.l_start) != flk64.l_start)
+      return Error(EOVERFLOW);
+
+    // Now copy back into flk, in case flk64 got modified
+    flk->l_type = flk64.l_type;
+    flk->l_whence = flk64.l_whence;
+    flk->l_start = static_cast<decltype(flk->l_start)>(flk64.l_start);
+    flk->l_len = static_cast<decltype(flk->l_len)>(flk64.l_len);
+    flk->l_pid = flk64.l_pid;
+    return ret;
+  }
+  case F_GETOWN: {
+    struct f_owner_ex fex;
+    int ret = syscall_impl<int>(FCNTL_SYSCALL_ID, fd, F_GETOWN_EX, &fex);
+    if (ret < 0)
+      return Error(-ret);
+    return fex.type == F_OWNER_PGRP ? -fex.pid : fex.pid;
+  }
+#ifdef SYS_fcntl64
+  case F_GETLK: {
+    if constexpr (FCNTL_SYSCALL_ID == SYS_fcntl64)
+      cmd = F_GETLK64;
+    break;
+  }
+  case F_SETLK: {
+    if constexpr (FCNTL_SYSCALL_ID == SYS_fcntl64)
+      cmd = F_SETLK64;
+    break;
+  }
+  case F_SETLKW: {
+    if constexpr (FCNTL_SYSCALL_ID == SYS_fcntl64)
+      cmd = F_SETLKW64;
+    break;
+  }
+#endif
+  }
 
-LIBC_INLINE ErrorOr<int> fcntl(int fd, int cmd, long arg = 0) {
-  int ret = syscall_impl<int>(SYS_fcntl, fd, cmd, arg);
+  // Plain passthrough for all other commands. When only SYS_fcntl64 is
+  // available, F_GETLK/F_SETLK/F_SETLKW have been rewritten to their 64-bit
+  // variants by the cases above.
+  int ret = syscall_impl<int>(FCNTL_SYSCALL_ID, fd, cmd, arg);
   if (ret < 0)
     return Error(-ret);
   return ret;
diff --git a/libc/src/fcntl/linux/CMakeLists.txt b/libc/src/fcntl/linux/CMakeLists.txt
index be5fd4fa8f44b..a235a99272636 100644
--- a/libc/src/fcntl/linux/CMakeLists.txt
+++ b/libc/src/fcntl/linux/CMakeLists.txt
@@ -19,6 +19,7 @@ add_entrypoint_object(
     ../fcntl.h
   DEPENDS
     libc.hdr.fcntl_macros
+    libc.src.__support.OSUtil.linux.syscall_wrappers.fcntl
     libc.src.__support.OSUtil.osutil
     libc.src.errno.errno
 )
diff --git a/libc/src/fcntl/linux/fcntl.cpp b/libc/src/fcntl/linux/fcntl.cpp
index fd9c48eb562f7..7a5f955c60a52 100644
--- a/libc/src/fcntl/linux/fcntl.cpp
+++ b/libc/src/fcntl/linux/fcntl.cpp
@@ -8,7 +8,7 @@
 
 #include "src/fcntl/fcntl.h"
 
-#include "src/__support/OSUtil/fcntl.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/fcntl.h"
 #include "src/__support/common.h"
 #include "src/__support/libc_errno.h"
 #include "src/__support/macros/config.h"
@@ -24,7 +24,7 @@ LLVM_LIBC_FUNCTION(int, fcntl, (int fd, int cmd, ...)) {
   arg = va_arg(varargs, void *);
   va_end(varargs);
 
-  auto result = LIBC_NAMESPACE::internal::fcntl(fd, cmd, arg);
+  auto result = LIBC_NAMESPACE::linux_syscalls::fcntl(fd, cmd, arg);
 
   if (!result.has_value()) {
     libc_errno = result.error();
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 56ef8876c9e2d..3765b06a9211d 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -1552,7 +1552,7 @@ libc_support_library(
         ":__support_file_file",
         ":__support_libc_errno",
         ":__support_macros_config",
-        ":__support_osutil_fcntl",
+        ":__support_osutil_linux_syscall_wrappers_fcntl",
         ":__support_osutil_linux_syscall_wrappers_lseek",
         ":__support_osutil_linux_syscall_wrappers_open",
         ":__support_osutil_syscall",
@@ -1635,6 +1635,7 @@ libc_support_library(
         ":__support_common",
         ":__support_error_or",
         ":__support_macros_config",
+        ":__support_osutil_linux_syscall_wrappers_fcntl",
         ":__support_osutil_syscall",
         ":hdr_fcntl_macros",
     ],
@@ -2804,9 +2805,8 @@ libc_support_library(
 )
 
 libc_support_library(
-    name = "__support_osutil_fcntl",
-    srcs = ["src/__support/OSUtil/linux/fcntl.cpp"],
-    hdrs = ["src/__support/OSUtil/fcntl.h"],
+    name = "__support_osutil_linux_syscall_wrappers_fcntl",
+    hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/fcntl.h"],
     target_compatible_with = select({
         "@platforms//os:linux": [],
         "//conditions:default": ["@platforms//:incompatible"],
@@ -2818,7 +2818,6 @@ libc_support_library(
         ":__support_osutil_syscall",
         ":hdr_errno_macros",
         ":hdr_fcntl_macros",
-        ":types_mode_t",
         ":types_off_t",
         ":types_struct_f_owner_ex",
         ":types_struct_flock",
@@ -14258,7 +14257,7 @@ libc_function(
         ":__support_common",
         ":__support_libc_errno",
         ":__support_macros_config",
-        ":__support_osutil_fcntl",
+        ":__support_osutil_linux_syscall_wrappers_fcntl",
         ":errno",
     ],
 )

>From e85b4dcff85487273b29fcd675a6d49f37f7bf54 Mon Sep 17 00:00:00 2001
From: "Mikhail R. Gadelha" <mikhail at igalia.com>
Date: Tue, 7 Jul 2026 12:14:25 -0300
Subject: [PATCH 2/2] Code style

Signed-off-by: Mikhail R. Gadelha <mikhail at igalia.com>
---
 libc/src/__support/File/linux/file.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/__support/File/linux/file.cpp b/libc/src/__support/File/linux/file.cpp
index c526f2dd01411..82395f9774ca7 100644
--- a/libc/src/__support/File/linux/file.cpp
+++ b/libc/src/__support/File/linux/file.cpp
@@ -139,7 +139,7 @@ ErrorOr<LinuxFile *> create_file_from_fd(int fd, const char *mode) {
       !(fd_flags & O_APPEND)) {
     do_seek = true;
     if (!linux_syscalls::fcntl(fd, F_SETFL,
-                         reinterpret_cast<void *>(fd_flags | O_APPEND))
+                               reinterpret_cast<void *>(fd_flags | O_APPEND))
              .has_value()) {
       return Error(EBADF);
     }



More information about the libc-commits mailing list