[libc-commits] [libc] Sys call migrations of stdio and unistd (PR #196403)

via libc-commits libc-commits at lists.llvm.org
Thu May 7 12:46:18 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Jeff Bailey (kaladron)

<details>
<summary>Changes</summary>

These two changes complement one another.  The first is another in the series of syscall migrations.  The second gets rid of a helper file that was being used to do lseek calls directly so that we can delete the header.  They're logically a bit separate, so I've split them into two and intend to commit them without squashing.

---

Patch is 53.11 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/196403.diff


35 Files Affected:

- (modified) libc/src/__support/File/linux/CMakeLists.txt (+1-3) 
- (modified) libc/src/__support/File/linux/file.cpp (+2-5) 
- (removed) libc/src/__support/File/linux/lseekImpl.h (-52) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt (+178) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/access.h (+43) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/chdir.h (+36) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/dup.h (+36) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/dup2.h (+55) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/dup3.h (+36) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/faccessat.h (+43) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/fchdir.h (+36) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/fsync.h (+36) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/lseek.h (+55) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/readlink.h (+46) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/readlinkat.h (+38) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/rename.h (+47) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/rmdir.h (+43) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/unlinkat.h (+36) 
- (modified) libc/src/stdio/linux/CMakeLists.txt (+1-3) 
- (modified) libc/src/stdio/linux/rename.cpp (+7-10) 
- (modified) libc/src/unistd/linux/CMakeLists.txt (+14-51) 
- (modified) libc/src/unistd/linux/access.cpp (+4-15) 
- (modified) libc/src/unistd/linux/chdir.cpp (+4-6) 
- (modified) libc/src/unistd/linux/dup.cpp (+5-7) 
- (modified) libc/src/unistd/linux/dup2.cpp (+5-33) 
- (modified) libc/src/unistd/linux/dup3.cpp (+7-9) 
- (modified) libc/src/unistd/linux/faccessat.cpp (+4-13) 
- (modified) libc/src/unistd/linux/fchdir.cpp (+4-6) 
- (modified) libc/src/unistd/linux/fsync.cpp (+5-7) 
- (modified) libc/src/unistd/linux/lseek.cpp (+4-9) 
- (modified) libc/src/unistd/linux/readlink.cpp (+5-16) 
- (modified) libc/src/unistd/linux/readlinkat.cpp (+5-9) 
- (modified) libc/src/unistd/linux/rmdir.cpp (+4-15) 
- (modified) libc/src/unistd/linux/unlink.cpp (+4-14) 
- (modified) libc/src/unistd/linux/unlinkat.cpp (+4-12) 


``````````diff
diff --git a/libc/src/__support/File/linux/CMakeLists.txt b/libc/src/__support/File/linux/CMakeLists.txt
index c046dd4066900..2becb385e44d9 100644
--- a/libc/src/__support/File/linux/CMakeLists.txt
+++ b/libc/src/__support/File/linux/CMakeLists.txt
@@ -5,17 +5,15 @@ add_object_library(
     file.cpp
   HDRS
     file.h
-    lseekImpl.h
   DEPENDS
     libc.hdr.fcntl_macros
     libc.hdr.stdio_macros
-    libc.hdr.stdint_proxy
-    libc.hdr.types.off_t
     libc.hdr.types.FILE
     libc.include.sys_syscall
     libc.include.sys_stat
     libc.src.__support.CPP.new
     libc.src.__support.OSUtil.osutil
+    libc.src.__support.OSUtil.linux.syscall_wrappers.lseek
     libc.src.__support.error_or
     libc.src.__support.File.file
     libc.src.errno.errno
diff --git a/libc/src/__support/File/linux/file.cpp b/libc/src/__support/File/linux/file.cpp
index 13065300e5a34..10a6f2a97dc41 100644
--- a/libc/src/__support/File/linux/file.cpp
+++ b/libc/src/__support/File/linux/file.cpp
@@ -12,8 +12,8 @@
 #include "hdr/types/off_t.h"
 #include "src/__support/CPP/new.h"
 #include "src/__support/File/file.h"
-#include "src/__support/File/linux/lseekImpl.h"
 #include "src/__support/OSUtil/fcntl.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/lseek.h"
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/alloc-checker.h"
 #include "src/__support/libc_errno.h" // For error macros
@@ -47,10 +47,7 @@ FileIOResult linux_file_read(File *f, void *buf, size_t size) {
 
 ErrorOr<off_t> linux_file_seek(File *f, off_t offset, int whence) {
   auto *lf = reinterpret_cast<LinuxFile *>(f);
-  auto result = internal::lseekimpl(lf->get_fd(), offset, whence);
-  if (!result.has_value())
-    return result.error();
-  return result.value();
+  return linux_syscalls::lseek(lf->get_fd(), offset, whence);
 }
 
 int linux_file_close(File *f) {
diff --git a/libc/src/__support/File/linux/lseekImpl.h b/libc/src/__support/File/linux/lseekImpl.h
deleted file mode 100644
index 47df99ae84b90..0000000000000
--- a/libc/src/__support/File/linux/lseekImpl.h
+++ /dev/null
@@ -1,52 +0,0 @@
-//===-- Linux implementation of lseek -------------------------------------===//
-//
-// 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_FILE_LINUX_LSEEKIMPL_H
-#define LLVM_LIBC_SRC___SUPPORT_FILE_LINUX_LSEEKIMPL_H
-
-#include "hdr/stdint_proxy.h" // For uint64_t.
-#include "hdr/types/off_t.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/libc_errno.h"
-#include "src/__support/macros/config.h"
-
-#include <sys/syscall.h> // For syscall numbers.
-
-namespace LIBC_NAMESPACE_DECL {
-namespace internal {
-
-LIBC_INLINE ErrorOr<off_t> lseekimpl(int fd, off_t offset, int whence) {
-  off_t result;
-#ifdef SYS_lseek
-  result = LIBC_NAMESPACE::syscall_impl<off_t>(SYS_lseek, fd, offset, whence);
-  if (result < 0)
-    return Error(-static_cast<int>(result));
-#elif defined(SYS_llseek) || defined(SYS__llseek)
-  static_assert(sizeof(size_t) == 4, "size_t must be 32 bits.");
-#ifdef SYS_llseek
-  constexpr long LLSEEK_SYSCALL_NO = SYS_llseek;
-#elif defined(SYS__llseek)
-  constexpr long LLSEEK_SYSCALL_NO = SYS__llseek;
-#endif
-  off_t offset_64 = offset;
-  int ret = LIBC_NAMESPACE::syscall_impl<int>(
-      LLSEEK_SYSCALL_NO, fd, offset_64 >> 32, offset_64, &result, whence);
-  if (ret < 0)
-    return Error(-ret);
-#else
-#error "lseek, llseek and _llseek syscalls not available."
-#endif
-  return result;
-}
-
-} // namespace internal
-} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC___SUPPORT_FILE_LINUX_LSEEKIMPL_H
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 6418d6f83dbfa..bbe76fece3bdd 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -365,3 +365,181 @@ add_header_library(
     libc.hdr.fcntl_macros
     libc.include.sys_syscall
 )
+
+add_header_library(
+  unlinkat
+  HDRS
+    unlinkat.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.include.sys_syscall
+)
+
+add_header_library(
+  rmdir
+  HDRS
+    rmdir.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.hdr.fcntl_macros
+    libc.include.sys_syscall
+)
+
+add_header_library(
+  chdir
+  HDRS
+    chdir.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.include.sys_syscall
+)
+
+add_header_library(
+  fchdir
+  HDRS
+    fchdir.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.include.sys_syscall
+)
+
+add_header_library(
+  fsync
+  HDRS
+    fsync.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.include.sys_syscall
+)
+
+
+add_header_library(
+  dup
+  HDRS
+    dup.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.include.sys_syscall
+)
+
+add_header_library(
+  dup2
+  HDRS
+    dup2.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.hdr.fcntl_macros
+    libc.include.sys_syscall
+)
+
+add_header_library(
+  dup3
+  HDRS
+    dup3.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.include.sys_syscall
+)
+
+add_header_library(
+  access
+  HDRS
+    access.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.hdr.fcntl_macros
+    libc.include.sys_syscall
+)
+
+add_header_library(
+  faccessat
+  HDRS
+    faccessat.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.include.sys_syscall
+)
+
+add_header_library(
+  readlink
+  HDRS
+    readlink.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.hdr.fcntl_macros
+    libc.hdr.types.ssize_t
+    libc.include.sys_syscall
+)
+
+add_header_library(
+  readlinkat
+  HDRS
+    readlinkat.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.hdr.types.ssize_t
+    libc.include.sys_syscall
+)
+
+add_header_library(
+  rename
+  HDRS
+    rename.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.hdr.fcntl_macros
+    libc.include.sys_syscall
+)
+
+add_header_library(
+  lseek
+  HDRS
+    lseek.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.hdr.stdint_proxy
+    libc.hdr.types.off_t
+    libc.include.sys_syscall
+)
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/access.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/access.h
new file mode 100644
index 0000000000000..3f3a3bd343901
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/access.h
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for access.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_ACCESS_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_ACCESS_H
+
+#include "hdr/fcntl_macros.h"
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#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 linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> access(const char *path, int mode) {
+#ifdef SYS_access
+  int ret = syscall_impl<int>(SYS_access, path, mode);
+#elif defined(SYS_faccessat)
+  int ret = syscall_impl<int>(SYS_faccessat, AT_FDCWD, path, mode, 0);
+#else
+#error "access and faccessat syscalls not available."
+#endif
+  if (ret < 0)
+    return Error(-ret);
+  return ret;
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_ACCESS_H
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/chdir.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/chdir.h
new file mode 100644
index 0000000000000..3bd87ca0f488f
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/chdir.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for chdir.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_CHDIR_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_CHDIR_H
+
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#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 linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> chdir(const char *path) {
+  int ret = syscall_impl<int>(SYS_chdir, path);
+  if (ret < 0)
+    return Error(-ret);
+  return ret;
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_CHDIR_H
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/dup.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/dup.h
new file mode 100644
index 0000000000000..3d54b684bd66e
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/dup.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for dup.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_DUP_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_DUP_H
+
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#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 linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> dup(int fd) {
+  int ret = syscall_impl<int>(SYS_dup, fd);
+  if (ret < 0)
+    return Error(-ret);
+  return ret;
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_DUP_H
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/dup2.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/dup2.h
new file mode 100644
index 0000000000000..49f37134bd5f5
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/dup2.h
@@ -0,0 +1,55 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for dup2.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_DUP2_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_DUP2_H
+
+#include "hdr/fcntl_macros.h"
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#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 linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> dup2(int oldfd, int newfd) {
+#ifdef SYS_dup2
+  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);
+  }
+  int ret = syscall_impl<int>(SYS_dup3, oldfd, newfd, 0);
+#else
+#error "dup2 and dup3 syscalls not available."
+#endif
+  if (ret < 0)
+    return Error(-ret);
+  return ret;
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_DUP2_H
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/dup3.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/dup3.h
new file mode 100644
index 0000000000000..3be0ad4526e90
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/dup3.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for dup3.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_DUP3_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_DUP3_H
+
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#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 linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> dup3(int oldfd, int newfd, int flags) {
+  int ret = syscall_impl<int>(SYS_dup3, oldfd, newfd, flags);
+  if (ret < 0)
+    return Error(-ret);
+  return ret;
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_DUP3_H
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/faccessat.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/faccessat.h
new file mode 100644
index 0000000000000..83fd7e617fb8a
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/faccessat.h
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for faccessat.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FACCESSAT_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FACCESSAT_H
+
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#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 linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> faccessat(int dfd, const char *path, int mode,
+                                   int flags) {
+#ifdef SYS_faccessat2
+  int ret = syscall_impl<int>(SYS_faccessat2, dfd, path, mode, flags);
+#elif defined(SYS_faccessat)
+  int ret = syscall_impl<int>(SYS_faccessat, dfd, path, mode, flags);
+#else
+#error "faccessat2 and faccessat syscalls not available."
+#endif
+  if (ret < 0)
+    return Error(-ret);
+  return ret;
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FACCESSAT_H
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/fchdir.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/fchdir.h
new file mode 100644
index 0000000000000..2830bb763a86a
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/fchdir.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for fchdir.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FCHDIR_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FCHDIR_H
+
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#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 linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> fchdir(int fd) {
+  int ret = syscall_impl<int>(SYS_fchdir, fd);
+  if (ret < 0)
+    return Error(-ret);
+  return ret;
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FCHDIR_H
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/fsync.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/fsync.h
new file mode 100644
index 0000000000000..1ebbca23f3019
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/fsync.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for fsync.
+///
+//===--------------------------------------------------------------...
[truncated]

``````````

</details>


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


More information about the libc-commits mailing list