[libc-commits] [libc] [libc] Migrate filesystem syscall wrappers to syscall_checked (PR #225636)

via libc-commits libc-commits at lists.llvm.org
Wed Sep 23 01:21:26 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Pavel Labath (labath)

<details>
<summary>Changes</summary>

Migrate a batch of related filesystem/path syscall wrappers to use syscall_checked instead of manual syscall_impl error checking.

While in there:
- update file headers to the new style
- reformat includes into a single block so clang-format can sort them

Assisted-by: Gemini

---

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


18 Files Affected:

- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/access.h (+3-6) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/chdir.h (+2-5) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/chmod.h (+4-7) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/faccessat.h (+3-6) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/fchdir.h (+2-5) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/fchmod.h (+2-5) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/getcwd.h (+5-8) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/link.h (+11-9) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/mkdir.h (+3-6) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/mkdirat.h (+2-5) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/readlink.h (+3-7) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/readlinkat.h (+2-5) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/rename.h (+6-9) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/rmdir.h (+3-6) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/statx.h (+2-5) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/unlink.h (+10-8) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/unlinkat.h (+2-5) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/utimensat.h (+10-10) 


``````````diff
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/access.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/access.h
index 8fa68109cfed0..5548875bd8d66 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/access.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/access.h
@@ -15,7 +15,7 @@
 #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/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -26,15 +26,12 @@ namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<int> access(const char *path, int mode) {
 #ifdef SYS_faccessat
-  int ret = syscall_impl<int>(SYS_faccessat, AT_FDCWD, path, mode, 0);
+  return syscall_checked<int>(SYS_faccessat, AT_FDCWD, path, mode, 0);
 #elif defined(SYS_access)
-  int ret = syscall_impl<int>(SYS_access, path, mode);
+  return syscall_checked<int>(SYS_access, path, mode);
 #else
 #error "access and faccessat syscalls not available."
 #endif
-  if (ret < 0)
-    return Error(-ret);
-  return ret;
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/chdir.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/chdir.h
index 3bd87ca0f488f..cb6e149a5945a 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/chdir.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/chdir.h
@@ -14,7 +14,7 @@
 #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/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -24,10 +24,7 @@ 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;
+  return syscall_checked<int>(SYS_chdir, path);
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/chmod.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/chmod.h
index 42b0d3db98326..d2937c61651fa 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/chmod.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/chmod.h
@@ -16,7 +16,7 @@
 
 #include "hdr/fcntl_macros.h"
 #include "hdr/types/mode_t.h"
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -27,18 +27,15 @@ namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<int> chmod(const char *path, mode_t mode) {
 #ifdef SYS_fchmodat
-  int ret = syscall_impl<int>(SYS_fchmodat, AT_FDCWD, path, mode, 0);
+  return syscall_checked<int>(SYS_fchmodat, AT_FDCWD, path, mode, 0);
 #elif defined(SYS_fchmodat2)
-  int ret = syscall_impl<int>(SYS_fchmodat2, AT_FDCWD, path, mode, 0,
+  return syscall_checked<int>(SYS_fchmodat2, AT_FDCWD, path, mode, 0,
                               AT_SYMLINK_NOFOLLOW);
 #elif defined(SYS_chmod)
-  int ret = syscall_impl<int>(SYS_chmod, path, mode);
+  return syscall_checked<int>(SYS_chmod, path, mode);
 #else
 #error "chmod, fchmodat and fchmodat2 syscalls not available."
 #endif
-  if (ret < 0)
-    return Error(-ret);
-  return ret;
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/faccessat.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/faccessat.h
index 83fd7e617fb8a..038613c05805e 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/faccessat.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/faccessat.h
@@ -14,7 +14,7 @@
 #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/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -26,15 +26,12 @@ 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);
+  return syscall_checked<int>(SYS_faccessat2, dfd, path, mode, flags);
 #elif defined(SYS_faccessat)
-  int ret = syscall_impl<int>(SYS_faccessat, dfd, path, mode, flags);
+  return syscall_checked<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
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/fchdir.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/fchdir.h
index 2830bb763a86a..25b78880b18eb 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/fchdir.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/fchdir.h
@@ -14,7 +14,7 @@
 #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/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -24,10 +24,7 @@ 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;
+  return syscall_checked<int>(SYS_fchdir, fd);
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/fchmod.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/fchmod.h
index 4760a821726e1..a83257bbe709d 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/fchmod.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/fchmod.h
@@ -15,7 +15,7 @@
 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FCHMOD_H
 
 #include "hdr/types/mode_t.h"
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -25,10 +25,7 @@ namespace LIBC_NAMESPACE_DECL {
 namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<int> fchmod(int fd, mode_t mode) {
-  int ret = syscall_impl<int>(SYS_fchmod, fd, mode);
-  if (ret < 0)
-    return Error(-ret);
-  return ret;
+  return syscall_checked<int>(SYS_fchmod, fd, mode);
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/getcwd.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/getcwd.h
index f0aa9cb3fbab8..19b8d9bc78116 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/getcwd.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/getcwd.h
@@ -16,28 +16,25 @@
 
 #include "hdr/errno_macros.h"
 #include "hdr/types/ssize_t.h"
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #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<ssize_t> getcwd(char *buf, size_t size) {
-  ssize_t ret = syscall_impl<ssize_t>(SYS_getcwd, buf, size);
-  if (ret < 0) {
-    return Error(static_cast<int>(-ret));
-  }
+  auto ret = syscall_checked<ssize_t>(SYS_getcwd, buf, size);
+  if (!ret)
+    return ret;
 
   // Return ENOENT for unreachable paths. This can occur, for example,
   // when getcwd is called in a directory after `chroot` has switched
   // the filesystem root.
-  if (ret == 0 || buf[0] != '/') {
+  if (*ret == 0 || buf[0] != '/')
     return Error(ENOENT);
-  }
 
   return ret;
 }
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/link.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/link.h
index 7e721e46d4208..b542e17e2790e 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/link.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/link.h
@@ -1,16 +1,21 @@
-//===-- Implementation header for link --------------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // 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 link.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_SYSCALL_WRAPPERS_LINK_H
 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_SYSCALL_WRAPPERS_LINK_H
 
-#include "hdr/fcntl_macros.h"                   // AT_FDCWD
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "hdr/fcntl_macros.h"
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -21,16 +26,13 @@ namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<int> link(const char *oldpath, const char *newpath) {
 #ifdef SYS_linkat
-  int ret =
-      syscall_impl<int>(SYS_linkat, AT_FDCWD, oldpath, AT_FDCWD, newpath, 0);
+  return syscall_checked<int>(SYS_linkat, AT_FDCWD, oldpath, AT_FDCWD, newpath,
+                              0);
 #elif defined(SYS_link)
-  int ret = syscall_impl<int>(SYS_link, oldpath, newpath);
+  return syscall_checked<int>(SYS_link, oldpath, newpath);
 #else
 #error "link and linkat syscalls not available."
 #endif
-  if (ret < 0)
-    return Error(-static_cast<int>(ret));
-  return ret;
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/mkdir.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/mkdir.h
index b5002914c5ec0..4b281a0134f24 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/mkdir.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/mkdir.h
@@ -16,7 +16,7 @@
 
 #include "hdr/fcntl_macros.h"
 #include "hdr/types/mode_t.h"
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -27,13 +27,10 @@ namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<int> mkdir(const char *path, mode_t mode) {
 #ifdef SYS_mkdirat
-  int ret = syscall_impl<int>(SYS_mkdirat, AT_FDCWD, path, mode);
+  return syscall_checked<int>(SYS_mkdirat, AT_FDCWD, path, mode);
 #else
-  int ret = syscall_impl<int>(SYS_mkdir, path, mode);
+  return syscall_checked<int>(SYS_mkdir, path, mode);
 #endif
-  if (ret < 0)
-    return Error(-ret);
-  return ret;
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/mkdirat.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/mkdirat.h
index 70e67e3fb7809..224364f1af984 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/mkdirat.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/mkdirat.h
@@ -15,7 +15,7 @@
 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_MKDIRAT_H
 
 #include "hdr/types/mode_t.h"
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -25,10 +25,7 @@ namespace LIBC_NAMESPACE_DECL {
 namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<int> mkdirat(int dfd, const char *path, mode_t mode) {
-  int ret = syscall_impl<int>(SYS_mkdirat, dfd, path, mode);
-  if (ret < 0)
-    return Error(-ret);
-  return ret;
+  return syscall_checked<int>(SYS_mkdirat, dfd, path, mode);
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/readlink.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/readlink.h
index 0c2e01b2b4d80..60178bc1e8439 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/readlink.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/readlink.h
@@ -16,7 +16,7 @@
 
 #include "hdr/fcntl_macros.h"
 #include "hdr/types/ssize_t.h"
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -28,16 +28,12 @@ namespace linux_syscalls {
 LIBC_INLINE ErrorOr<ssize_t> readlink(const char *path, char *buf,
                                       size_t bufsiz) {
 #ifdef SYS_readlinkat
-  ssize_t ret =
-      syscall_impl<ssize_t>(SYS_readlinkat, AT_FDCWD, path, buf, bufsiz);
+  return syscall_checked<ssize_t>(SYS_readlinkat, AT_FDCWD, path, buf, bufsiz);
 #elif defined(SYS_readlink)
-  ssize_t ret = syscall_impl<ssize_t>(SYS_readlink, path, buf, bufsiz);
+  return syscall_checked<ssize_t>(SYS_readlink, path, buf, bufsiz);
 #else
 #error "readlink and readlinkat syscalls not available."
 #endif
-  if (ret < 0)
-    return Error(-static_cast<int>(ret));
-  return ret;
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/readlinkat.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/readlinkat.h
index d65573c9d8aee..2ab6fe9846148 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/readlinkat.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/readlinkat.h
@@ -15,7 +15,7 @@
 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_READLINKAT_H
 
 #include "hdr/types/ssize_t.h"
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -26,10 +26,7 @@ namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<ssize_t> readlinkat(int dfd, const char *path, char *buf,
                                         size_t bufsiz) {
-  ssize_t ret = syscall_impl<ssize_t>(SYS_readlinkat, dfd, path, buf, bufsiz);
-  if (ret < 0)
-    return Error(-static_cast<int>(ret));
-  return ret;
+  return syscall_checked<ssize_t>(SYS_readlinkat, dfd, path, buf, bufsiz);
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/rename.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/rename.h
index ec0be35b27ab8..25c307e4d9bd9 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/rename.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/rename.h
@@ -15,7 +15,7 @@
 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_RENAME_H
 
 #include "hdr/fcntl_macros.h"
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -26,19 +26,16 @@ namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<int> rename(const char *oldpath, const char *newpath) {
 #ifdef SYS_renameat2
-  int ret =
-      syscall_impl<int>(SYS_renameat2, AT_FDCWD, oldpath, AT_FDCWD, newpath, 0);
+  return syscall_checked<int>(SYS_renameat2, AT_FDCWD, oldpath, AT_FDCWD,
+                              newpath, 0);
 #elif defined(SYS_renameat)
-  int ret =
-      syscall_impl<int>(SYS_renameat, AT_FDCWD, oldpath, AT_FDCWD, newpath);
+  return syscall_checked<int>(SYS_renameat, AT_FDCWD, oldpath, AT_FDCWD,
+                              newpath);
 #elif defined(SYS_rename)
-  int ret = syscall_impl<int>(SYS_rename, oldpath, newpath);
+  return syscall_checked<int>(SYS_rename, oldpath, newpath);
 #else
 #error "rename, renameat and renameat2 syscalls not available."
 #endif
-  if (ret < 0)
-    return Error(-ret);
-  return ret;
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/rmdir.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/rmdir.h
index 0d1cf7a0e3678..9ff7abd263f54 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/rmdir.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/rmdir.h
@@ -15,7 +15,7 @@
 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_RMDIR_H
 
 #include "hdr/fcntl_macros.h"
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -26,15 +26,12 @@ namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<int> rmdir(const char *path) {
 #ifdef SYS_unlinkat
-  int ret = syscall_impl<int>(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
+  return syscall_checked<int>(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
 #elif defined(SYS_rmdir)
-  int ret = syscall_impl<int>(SYS_rmdir, path);
+  return syscall_checked<int>(SYS_rmdir, path);
 #else
 #error "rmdir and unlinkat syscalls not available."
 #endif
-  if (ret < 0)
-    return Error(-ret);
-  return ret;
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/statx.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/statx.h
index c65a74fc3ec08..ae40dab3594d0 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/statx.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/statx.h
@@ -14,7 +14,7 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_STATX_H
 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_STATX_H
 
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -25,10 +25,7 @@ namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<int> statx(int dirfd, const char *path, int flags,
                                unsigned int mask, void *statxbuf) {
-  int ret = syscall_impl<int>(SYS_statx, dirfd, path, flags, mask, statxbuf);
-  if (ret < 0)
-    return Error(-ret);
-  return ret;
+  return syscall_checked<int>(SYS_statx, dirfd, path, flags, mask, statxbuf);
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/unlink.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/unlink.h
index e04ebada8cb81..b235c18a0a055 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/unlink.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/unlink.h
@@ -1,16 +1,21 @@
-//===-- Implementation header for unlink ------------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // 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 unlink.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_SYSCALL_WRAPPERS_UNLINK_H
 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_SYSCALL_WRAPPERS_UNLINK_H
 
-#include "hdr/fcntl_macros.h"                   // AT_FDCWD
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "hdr/fcntl_macros.h"
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -2...
[truncated]

``````````

</details>


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


More information about the libc-commits mailing list