llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-libc Author: Connector Switch (c8ef) <details> <summary>Changes</summary> This PR move fchown behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md. --- Full diff: https://github.com/llvm/llvm-project/pull/241768.diff 5 Files Affected: - (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt (+14) - (added) libc/src/__support/OSUtil/linux/syscall_wrappers/fchown.h (+35) - (modified) libc/src/unistd/linux/CMakeLists.txt (+5-3) - (modified) libc/src/unistd/linux/fchown.cpp (+10-9) - (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+36) ``````````diff diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt index 7fd9991be0e16..a8250b57599e7 100644 --- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt +++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt @@ -1221,6 +1221,20 @@ add_header_library( libc.src.__support.macros.config ) +add_header_library( + fchown + HDRS + fchown.h + DEPENDS + libc.hdr.types.gid_t + libc.hdr.types.uid_t + libc.include.sys_syscall + libc.src.__support.OSUtil.osutil + libc.src.__support.common + libc.src.__support.error_or + libc.src.__support.macros.config +) + add_header_library( fchownat HDRS diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/fchown.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/fchown.h new file mode 100644 index 0000000000000..a7d8f396a9850 --- /dev/null +++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/fchown.h @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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 fchown. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FCHOWN_H +#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FCHOWN_H + +#include "hdr/types/gid_t.h" +#include "hdr/types/uid_t.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 <sys/syscall.h> // For syscall numbers. + +namespace LIBC_NAMESPACE_DECL { +namespace linux_syscalls { + +LIBC_INLINE ErrorOr<int> fchown(int fildes, uid_t owner, gid_t group) { + return syscall_checked<int>(SYS_fchown, fildes, owner, group); +} + +} // namespace linux_syscalls +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FCHOWN_H diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt index 5a44bbd3d9caa..747ef41278eb8 100644 --- a/libc/src/unistd/linux/CMakeLists.txt +++ b/libc/src/unistd/linux/CMakeLists.txt @@ -164,10 +164,12 @@ add_entrypoint_object( HDRS ../fchown.h DEPENDS - libc.hdr.types.uid_t libc.hdr.types.gid_t - libc.include.sys_syscall - libc.src.__support.OSUtil.osutil + libc.hdr.types.uid_t + libc.src.__support.OSUtil.linux.syscall_wrappers.fchown + libc.src.__support.common + libc.src.__support.libc_errno + libc.src.__support.macros.config libc.src.errno.errno ) diff --git a/libc/src/unistd/linux/fchown.cpp b/libc/src/unistd/linux/fchown.cpp index 9cf3d139050c1..b7e1b62902df3 100644 --- a/libc/src/unistd/linux/fchown.cpp +++ b/libc/src/unistd/linux/fchown.cpp @@ -1,28 +1,29 @@ -//===-- Linux implementation of fchown ------------------------------------===// +//===----------------------------------------------------------------------===// // // 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 +/// Linux implementation for fchown. +/// +//===----------------------------------------------------------------------===// #include "src/unistd/fchown.h" -#include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/__support/OSUtil/linux/syscall_wrappers/fchown.h" #include "src/__support/common.h" - -#include "hdr/types/gid_t.h" -#include "hdr/types/uid_t.h" #include "src/__support/libc_errno.h" #include "src/__support/macros/config.h" -#include <sys/syscall.h> // For syscall numbers. namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(int, fchown, (int fildes, uid_t owner, gid_t group)) { - int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_fchown, fildes, owner, group); - if (ret < 0) { - libc_errno = -ret; + auto result = linux_syscalls::fchown(fildes, owner, group); + if (!result) { + libc_errno = result.error(); return -1; } return 0; diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index a1cc803e9b35e..e58ab7294982e 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -2833,6 +2833,23 @@ libc_support_library( ], ) +libc_support_library( + name = "__support_osutil_linux_syscall_wrappers_fchown", + hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/fchown.h"], + target_compatible_with = select({ + "@platforms//os:linux": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + deps = [ + ":__support_common", + ":__support_error_or", + ":__support_macros_config", + ":__support_osutil_syscall", + ":types_gid_t", + ":types_uid_t", + ], +) + libc_support_library( name = "__support_osutil_linux_syscall_wrappers_ftruncate", hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/ftruncate.h"], @@ -18845,6 +18862,25 @@ libc_function( ], ) +libc_function( + name = "fchown", + srcs = ["src/unistd/linux/fchown.cpp"], + hdrs = ["src/unistd/fchown.h"], + target_compatible_with = select({ + "@platforms//os:linux": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + deps = [ + ":__support_common", + ":__support_libc_errno", + ":__support_macros_config", + ":__support_osutil_linux_syscall_wrappers_fchown", + ":errno", + ":types_gid_t", + ":types_uid_t", + ], +) + libc_function( name = "fsync", srcs = ["src/unistd/linux/fsync.cpp"], `````````` </details> https://github.com/llvm/llvm-project/pull/241768 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
