[libc-commits] [libc] [libc] Migrate filesystem syscall wrappers to syscall_checked (PR #225636)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Wed Sep 23 01:20:45 PDT 2026
https://github.com/labath created https://github.com/llvm/llvm-project/pull/225636
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
>From 60b3ea14a257d2095e41ed431fcae80074055890 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Wed, 23 Sep 2026 07:38:31 +0000
Subject: [PATCH] [libc] Migrate filesystem syscall wrappers to syscall_checked
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
---
.../OSUtil/linux/syscall_wrappers/access.h | 9 +++------
.../OSUtil/linux/syscall_wrappers/chdir.h | 7 ++-----
.../OSUtil/linux/syscall_wrappers/chmod.h | 11 ++++------
.../OSUtil/linux/syscall_wrappers/faccessat.h | 9 +++------
.../OSUtil/linux/syscall_wrappers/fchdir.h | 7 ++-----
.../OSUtil/linux/syscall_wrappers/fchmod.h | 7 ++-----
.../OSUtil/linux/syscall_wrappers/getcwd.h | 13 +++++-------
.../OSUtil/linux/syscall_wrappers/link.h | 20 ++++++++++---------
.../OSUtil/linux/syscall_wrappers/mkdir.h | 9 +++------
.../OSUtil/linux/syscall_wrappers/mkdirat.h | 7 ++-----
.../OSUtil/linux/syscall_wrappers/readlink.h | 10 +++-------
.../linux/syscall_wrappers/readlinkat.h | 7 ++-----
.../OSUtil/linux/syscall_wrappers/rename.h | 15 ++++++--------
.../OSUtil/linux/syscall_wrappers/rmdir.h | 9 +++------
.../OSUtil/linux/syscall_wrappers/statx.h | 7 ++-----
.../OSUtil/linux/syscall_wrappers/unlink.h | 18 +++++++++--------
.../OSUtil/linux/syscall_wrappers/unlinkat.h | 7 ++-----
.../OSUtil/linux/syscall_wrappers/utimensat.h | 20 +++++++++----------
18 files changed, 75 insertions(+), 117 deletions(-)
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/access.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/access.h
index 8fa68109cfed06..5548875bd8d668 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 3bd87ca0f488f7..cb6e149a5945ab 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 42b0d3db983260..d2937c61651fa7 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 83fd7e617fb8ac..038613c05805e3 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 2830bb763a86a9..25b78880b18eb6 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 4760a821726e1a..a83257bbe709de 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 f0aa9cb3fbab8c..19b8d9bc781165 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 7e721e46d42083..b542e17e2790e8 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 b5002914c5ec02..4b281a0134f245 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 70e67e3fb78091..224364f1af9847 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 0c2e01b2b4d804..60178bc1e84396 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 d65573c9d8aee7..2ab6fe98461484 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 ec0be35b27ab8d..25c307e4d9bd94 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 0d1cf7a0e36785..9ff7abd263f544 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 c65a74fc3ec084..ae40dab3594d03 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 e04ebada8cb816..b235c18a0a0559 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"
@@ -21,15 +26,12 @@ namespace linux_syscalls {
LIBC_INLINE ErrorOr<int> unlink(const char *path) {
#ifdef SYS_unlinkat
- int ret = syscall_impl<int>(SYS_unlinkat, AT_FDCWD, path, 0);
+ return syscall_checked<int>(SYS_unlinkat, AT_FDCWD, path, 0);
#elif defined(SYS_unlink)
- int ret = syscall_impl<int>(SYS_unlink, path);
+ return syscall_checked<int>(SYS_unlink, path);
#else
#error "unlink and unlinkat syscalls not available."
#endif
- if (ret < 0)
- return Error(-static_cast<int>(ret));
- return 0;
}
} // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/unlinkat.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/unlinkat.h
index ffba729333fbdd..1e2155e5891da9 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/unlinkat.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/unlinkat.h
@@ -14,7 +14,7 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_UNLINKAT_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_UNLINKAT_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> unlinkat(int dfd, const char *path, int flags) {
- int ret = syscall_impl<int>(SYS_unlinkat, dfd, path, flags);
- if (ret < 0)
- return Error(-ret);
- return ret;
+ return syscall_checked<int>(SYS_unlinkat, dfd, path, flags);
}
} // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/utimensat.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/utimensat.h
index cbf79f5de2cbf2..635eef05cb0194 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/utimensat.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/utimensat.h
@@ -1,20 +1,24 @@
-//===-- Implementation header for utimensat ---------------------*- 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 utimensat.
+///
+//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_UTIMENSAT_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_UTIMENSAT_H
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "hdr/types/struct_timespec.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"
-
-#include "hdr/types/struct_timespec.h"
#include <sys/syscall.h> // For syscall numbers
namespace LIBC_NAMESPACE_DECL {
@@ -23,21 +27,17 @@ namespace linux_syscalls {
LIBC_INLINE ErrorOr<int> utimensat(int dirfd, const char *path,
const struct timespec times[2], int flags) {
#if defined(SYS_utimensat_time64)
- int ret = syscall_impl<int>(SYS_utimensat_time64, dirfd, path, times, flags);
+ return syscall_checked<int>(SYS_utimensat_time64, dirfd, path, times, flags);
#elif defined(SYS_utimensat)
static_assert(
sizeof(timespec::tv_nsec) == sizeof(long),
"This legacy syscall fallback is only safe on platforms where tv_nsec "
"matches the register size (long). It is unsafe on 32-bit platforms "
"with 64-bit tv_nsec.");
- int ret = syscall_impl<int>(SYS_utimensat, dirfd, path, times, flags);
+ return syscall_checked<int>(SYS_utimensat, dirfd, path, times, flags);
#else
#error "utimensat or utimensat_time64 syscalls not available."
#endif
-
- if (ret < 0)
- return Error(-static_cast<int>(ret));
- return ret;
}
} // namespace linux_syscalls
More information about the libc-commits
mailing list