https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/240781
This PR move gethostname behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md. >From fdd3ca55161e1d1e26bec2f2ffb06098f87b2079 Mon Sep 17 00:00:00 2001 From: c8ef <[email protected]> Date: Tue, 10 Nov 2026 18:44:47 +0800 Subject: [PATCH] [libc] Use a syscall wrapper for gethostname This PR move gethostname behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md. --- libc/src/unistd/linux/CMakeLists.txt | 6 ++++-- libc/src/unistd/linux/gethostname.cpp | 17 +++++++++------- .../llvm-project-overlay/libc/BUILD.bazel | 20 +++++++++++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt index 064ea546e0187b..530b0b1aae68e9 100644 --- a/libc/src/unistd/linux/CMakeLists.txt +++ b/libc/src/unistd/linux/CMakeLists.txt @@ -433,8 +433,10 @@ add_entrypoint_object( DEPENDS libc.hdr.types.size_t libc.hdr.types.struct_utsname - libc.include.sys_syscall - libc.src.__support.OSUtil.osutil + libc.src.__support.OSUtil.linux.syscall_wrappers.uname + libc.src.__support.common + libc.src.__support.libc_errno + libc.src.__support.macros.config libc.src.errno.errno libc.src.string.string_utils ) diff --git a/libc/src/unistd/linux/gethostname.cpp b/libc/src/unistd/linux/gethostname.cpp index f65fd36540b835..8a1fa954e0f7b0 100644 --- a/libc/src/unistd/linux/gethostname.cpp +++ b/libc/src/unistd/linux/gethostname.cpp @@ -1,23 +1,26 @@ -//===-- Linux implementation of gethostname -------------------------------===// +//===----------------------------------------------------------------------===// // // 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 of gethostname. +/// +//===----------------------------------------------------------------------===// #include "src/unistd/gethostname.h" #include "hdr/types/size_t.h" #include "hdr/types/struct_utsname.h" -#include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/__support/OSUtil/linux/syscall_wrappers/uname.h" #include "src/__support/common.h" #include "src/__support/libc_errno.h" #include "src/__support/macros/config.h" #include "src/string/string_utils.h" -#include <sys/syscall.h> // For syscall numbers. - namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t size)) { @@ -30,9 +33,9 @@ LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t size)) { // Because there is no SYS_gethostname syscall, we use uname to get the // hostname. utsname unameData; - int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_uname, &unameData); - if (ret < 0) { - libc_errno = static_cast<int>(-ret); + auto result = linux_syscalls::uname(&unameData); + if (!result) { + libc_errno = result.error(); return -1; } diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 689ae5d486f018..06b51a9af9acc5 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -18763,6 +18763,26 @@ libc_function( ], ) +libc_function( + name = "gethostname", + srcs = ["src/unistd/linux/gethostname.cpp"], + hdrs = ["src/unistd/gethostname.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_uname", + ":errno", + ":string_utils", + ":types_size_t", + ":types_struct_utsname", + ], +) + libc_function( name = "getpagesize", srcs = ["src/unistd/linux/getpagesize.cpp"], _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
