From c44b475213378bbb63e4bfbbc0b6d0bf05003055 Mon Sep 17 00:00:00 2001 From: ZakyHermawan Date: Fri, 21 Feb 2025 14:10:54 +0700 Subject: [PATCH 1/9] Implement gethostname Matching the behavior of glibc version 2.2 and later. If the size of the array name is not large enough, then anything might happen. In this case, what happens to the array name will be determined by the implementation of LIBC_NAMESPACE_DECL::strncpy Signed-off-by: ZakyHermawan --- libc/config/linux/aarch64/entrypoints.txt | 1 + libc/config/linux/riscv/entrypoints.txt | 1 + libc/config/linux/x86_64/entrypoints.txt | 1 + libc/include/unistd.yaml | 7 +++ libc/src/unistd/CMakeLists.txt | 7 +++ libc/src/unistd/gethostname.h | 22 ++++++++ libc/src/unistd/linux/CMakeLists.txt | 16 ++++++ libc/src/unistd/linux/gethostname.cpp | 62 +++++++++++++++++++++++ libc/test/src/unistd/CMakeLists.txt | 11 ++++ libc/test/src/unistd/gethostname_test.cpp | 28 ++++++++++ 10 files changed, 156 insertions(+) create mode 100644 libc/src/unistd/gethostname.h create mode 100644 libc/src/unistd/linux/gethostname.cpp create mode 100644 libc/test/src/unistd/gethostname_test.cpp diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index aac4017a0d845..6450e41b76dfe 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -327,6 +327,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.unistd.getcwd libc.src.unistd.getentropy libc.src.unistd.geteuid + libc.src.unistd.gethostname libc.src.unistd.getpid libc.src.unistd.getppid libc.src.unistd.getsid diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt index 6b006f0ecca89..10119b5f76d58 100644 --- a/libc/config/linux/riscv/entrypoints.txt +++ b/libc/config/linux/riscv/entrypoints.txt @@ -324,6 +324,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.unistd.ftruncate libc.src.unistd.getcwd libc.src.unistd.geteuid + libc.src.unistd.gethostname libc.src.unistd.getpid libc.src.unistd.getppid libc.src.unistd.getsid diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 35661004663c9..c4c2e1449ef97 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -326,6 +326,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.unistd.getcwd libc.src.unistd.getentropy libc.src.unistd.geteuid + libc.src.unistd.gethostname libc.src.unistd.getpid libc.src.unistd.getppid libc.src.unistd.getsid diff --git a/libc/include/unistd.yaml b/libc/include/unistd.yaml index 051e92b006741..3ba3ec71c25ce 100644 --- a/libc/include/unistd.yaml +++ b/libc/include/unistd.yaml @@ -141,6 +141,13 @@ functions: return_type: uid_t arguments: - type: void + - name: gethostname + standards: + - POSIX + return_type: int + arguments: + - type: char * + - type: size_t - name: getopt standards: - POSIX diff --git a/libc/src/unistd/CMakeLists.txt b/libc/src/unistd/CMakeLists.txt index b1a1716aa85c6..c66a3a4d0ed76 100644 --- a/libc/src/unistd/CMakeLists.txt +++ b/libc/src/unistd/CMakeLists.txt @@ -111,6 +111,13 @@ add_entrypoint_object( .${LIBC_TARGET_OS}.getcwd ) +add_entrypoint_object( + gethostname + ALIAS + DEPENDS + .${LIBC_TARGET_OS}.gethostname +) + add_entrypoint_object( getpid ALIAS diff --git a/libc/src/unistd/gethostname.h b/libc/src/unistd/gethostname.h new file mode 100644 index 0000000000000..ef1b2d5381de6 --- /dev/null +++ b/libc/src/unistd/gethostname.h @@ -0,0 +1,22 @@ +//===-- Implementation header for gethostname -------------------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_UNISTD_GETHOSTNAME_H +#define LLVM_LIBC_SRC_UNISTD_GETHOSTNAME_H + +#include "hdr/types/size_t.h" +#include "hdr/unistd_macros.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +int gethostname(char *name, size_t len); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_UNISTD_GETHOSTNAME_H diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt index 368593a3bb7b5..6ea8068a6f39c 100644 --- a/libc/src/unistd/linux/CMakeLists.txt +++ b/libc/src/unistd/linux/CMakeLists.txt @@ -193,6 +193,22 @@ add_entrypoint_object( libc.src.errno.errno ) +add_entrypoint_object( + gethostname + SRCS + gethostname.cpp + HDRS + ../gethostname.h + DEPENDS + libc.hdr.types.size_t + libc.include.sys_syscall + libc.include.sys_utsname + libc.src.__support.OSUtil.osutil + libc.src.errno.errno + libc.src.string.strlen + libc.src.string.strncpy +) + add_entrypoint_object( geteuid SRCS diff --git a/libc/src/unistd/linux/gethostname.cpp b/libc/src/unistd/linux/gethostname.cpp new file mode 100644 index 0000000000000..617d0197c73c7 --- /dev/null +++ b/libc/src/unistd/linux/gethostname.cpp @@ -0,0 +1,62 @@ +//===-- 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 +// +//===----------------------------------------------------------------------===// + +#include "src/unistd/gethostname.h" + +#include "hdr/types/size_t.h" +#include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +#include "src/string/strlen.h" +#include "src/string/strncpy.h" +#include "src/errno/libc_errno.h" + +#include // For syscall numbers. +#include + +namespace LIBC_NAMESPACE_DECL { + +// Matching the behavior of glibc version 2.2 and later. +// Copies up to len bytes from the returned nodename field into name. +LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t len)) { + + // Check for invalid pointer + if (name == nullptr) { + libc_errno = EFAULT; + return -1; + } + + struct utsname unameData; + int ret = LIBC_NAMESPACE::syscall_impl(SYS_uname, &unameData); + + // Checks if the length of the nodename was greater than or equal to len, and if it is, + // then the function returns -1 with errno set to ENAMETOOLONG. + // In this case, a terminating null byte is not included in the returned name. + if (strlen(unameData.nodename) >= len) + { + strncpy(name, unameData.nodename, len); + libc_errno = ENAMETOOLONG; + return -1; + } + + // If the size of the array name is not large enough (less than the size of nodename with null termination), then anything might happen. + // In this case, what happens to the array name will be determined by the implementation of LIBC_NAMESPACE_DECL::strncpy + strncpy(name, unameData.nodename, len); + + if (ret < 0) { + libc_errno = static_cast(-ret); + return -1; + } + + return 0; +} + +} // namespace LIBC_NAMESPACE_DECL + + diff --git a/libc/test/src/unistd/CMakeLists.txt b/libc/test/src/unistd/CMakeLists.txt index d1f3050e6cccf..0f01104044e34 100644 --- a/libc/test/src/unistd/CMakeLists.txt +++ b/libc/test/src/unistd/CMakeLists.txt @@ -374,6 +374,17 @@ add_libc_unittest( libc.src.unistd.unlinkat ) +add_libc_unittest( + gethostname_test + SUITE + libc_unistd_unittests + SRCS + gethostname_test.cpp + DEPENDS + libc.src.unistd.gethostname + libc.src.errno.errno +) + add_libc_unittest( getpid_test SUITE diff --git a/libc/test/src/unistd/gethostname_test.cpp b/libc/test/src/unistd/gethostname_test.cpp new file mode 100644 index 0000000000000..777f9664e7ee6 --- /dev/null +++ b/libc/test/src/unistd/gethostname_test.cpp @@ -0,0 +1,28 @@ +//===-- Unittests for 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 +// +//===----------------------------------------------------------------------===// + +#include "src/errno/libc_errno.h" +#include "src/unistd/gethostname.h" +#include "test/UnitTest/Test.h" + +TEST(LlvmLibcGetHostNameTest, GetCurrHostName) { + char hostbuffer[1024]; + int ret = LIBC_NAMESPACE::gethostname(hostbuffer, sizeof(hostbuffer)); + ASSERT_NE(ret, -1); + ASSERT_ERRNO_SUCCESS(); + + ret = LIBC_NAMESPACE::gethostname(hostbuffer, 0); + ASSERT_EQ(ret, -1); + ASSERT_ERRNO_EQ(ENAMETOOLONG); + + // test for invalid pointer + char* nptr = nullptr; + ret = LIBC_NAMESPACE::gethostname(nptr, 1); + ASSERT_EQ(ret, -1); + ASSERT_ERRNO_EQ(EFAULT); +} From 89494d2aba8bb9a52f9fc1831e09ff2570b1bf06 Mon Sep 17 00:00:00 2001 From: ZakyHermawan Date: Fri, 21 Feb 2025 14:37:03 +0700 Subject: [PATCH 2/9] style: fix clang-format issues Signed-off-by: ZakyHermawan --- libc/src/unistd/linux/gethostname.cpp | 20 +++++++++----------- libc/test/src/unistd/gethostname_test.cpp | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libc/src/unistd/linux/gethostname.cpp b/libc/src/unistd/linux/gethostname.cpp index 617d0197c73c7..61b0c3f968dbf 100644 --- a/libc/src/unistd/linux/gethostname.cpp +++ b/libc/src/unistd/linux/gethostname.cpp @@ -13,9 +13,9 @@ #include "src/__support/common.h" #include "src/__support/macros/config.h" +#include "src/errno/libc_errno.h" #include "src/string/strlen.h" #include "src/string/strncpy.h" -#include "src/errno/libc_errno.h" #include // For syscall numbers. #include @@ -25,7 +25,6 @@ namespace LIBC_NAMESPACE_DECL { // Matching the behavior of glibc version 2.2 and later. // Copies up to len bytes from the returned nodename field into name. LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t len)) { - // Check for invalid pointer if (name == nullptr) { libc_errno = EFAULT; @@ -35,18 +34,19 @@ LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t len)) { struct utsname unameData; int ret = LIBC_NAMESPACE::syscall_impl(SYS_uname, &unameData); - // Checks if the length of the nodename was greater than or equal to len, and if it is, - // then the function returns -1 with errno set to ENAMETOOLONG. - // In this case, a terminating null byte is not included in the returned name. - if (strlen(unameData.nodename) >= len) - { + // Checks if the length of the nodename was greater than or equal to len, and + // if it is, then the function returns -1 with errno set to ENAMETOOLONG. In + // this case, a terminating null byte is not included in the returned name. + if (strlen(unameData.nodename) >= len) { strncpy(name, unameData.nodename, len); libc_errno = ENAMETOOLONG; return -1; } - // If the size of the array name is not large enough (less than the size of nodename with null termination), then anything might happen. - // In this case, what happens to the array name will be determined by the implementation of LIBC_NAMESPACE_DECL::strncpy + // If the size of the array name is not large enough (less than the size of + // nodename with null termination), then anything might happen. In this case, + // what happens to the array name will be determined by the implementation of + // LIBC_NAMESPACE_DECL::strncpy strncpy(name, unameData.nodename, len); if (ret < 0) { @@ -58,5 +58,3 @@ LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t len)) { } } // namespace LIBC_NAMESPACE_DECL - - diff --git a/libc/test/src/unistd/gethostname_test.cpp b/libc/test/src/unistd/gethostname_test.cpp index 777f9664e7ee6..3becf748fb6c0 100644 --- a/libc/test/src/unistd/gethostname_test.cpp +++ b/libc/test/src/unistd/gethostname_test.cpp @@ -21,7 +21,7 @@ TEST(LlvmLibcGetHostNameTest, GetCurrHostName) { ASSERT_ERRNO_EQ(ENAMETOOLONG); // test for invalid pointer - char* nptr = nullptr; + char *nptr = nullptr; ret = LIBC_NAMESPACE::gethostname(nptr, 1); ASSERT_EQ(ret, -1); ASSERT_ERRNO_EQ(EFAULT); From 0cedfc2a542b2fe89de95d1b52e0dea106d9ce08 Mon Sep 17 00:00:00 2001 From: ZakyHermawan Date: Wed, 17 Sep 2025 12:26:54 +0700 Subject: [PATCH 3/9] change len to size, use internal implementation instead of calling other libc function, handle failed syscall, and correctly handle string copy Signed-off-by: ZakyHermawan --- libc/src/unistd/linux/gethostname.cpp | 33 ++++++++++++--------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/libc/src/unistd/linux/gethostname.cpp b/libc/src/unistd/linux/gethostname.cpp index 61b0c3f968dbf..7408b5f89b5ce 100644 --- a/libc/src/unistd/linux/gethostname.cpp +++ b/libc/src/unistd/linux/gethostname.cpp @@ -14,43 +14,38 @@ #include "src/__support/macros/config.h" #include "src/errno/libc_errno.h" -#include "src/string/strlen.h" -#include "src/string/strncpy.h" +#include "src/string/string_utils.h" #include // For syscall numbers. #include +#include + namespace LIBC_NAMESPACE_DECL { -// Matching the behavior of glibc version 2.2 and later. -// Copies up to len bytes from the returned nodename field into name. -LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t len)) { +LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t size)) { // Check for invalid pointer if (name == nullptr) { libc_errno = EFAULT; return -1; } + // Because there is no SYS_gethostname syscall, we use uname to get the hostname. struct utsname unameData; int ret = LIBC_NAMESPACE::syscall_impl(SYS_uname, &unameData); - - // Checks if the length of the nodename was greater than or equal to len, and - // if it is, then the function returns -1 with errno set to ENAMETOOLONG. In - // this case, a terminating null byte is not included in the returned name. - if (strlen(unameData.nodename) >= len) { - strncpy(name, unameData.nodename, len); - libc_errno = ENAMETOOLONG; + if (ret < 0) { + libc_errno = static_cast(-ret); return -1; } - // If the size of the array name is not large enough (less than the size of - // nodename with null termination), then anything might happen. In this case, - // what happens to the array name will be determined by the implementation of - // LIBC_NAMESPACE_DECL::strncpy - strncpy(name, unameData.nodename, len); + // Guarantee that the name will be null terminated. + // The amount of bytes copied is min(size + 1, strlen(nodename) + 1) + // +1 to account for the null terminator (the last copied byte is a NULL). + internal::strlcpy(name, unameData.nodename, size + 1); - if (ret < 0) { - libc_errno = static_cast(-ret); + // Checks if the length of the hostname was greater than or equal to size + if (internal::string_length(unameData.nodename) >= size) { + libc_errno = ENAMETOOLONG; return -1; } From c23492b66971d9f8800f234be1ddcf090f44d0bd Mon Sep 17 00:00:00 2001 From: ZakyHermawan Date: Wed, 17 Sep 2025 12:37:09 +0700 Subject: [PATCH 4/9] remove unnecessary strlen and strncpy from CMakeLists.txt Signed-off-by: ZakyHermawan --- libc/src/unistd/linux/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt index 6ea8068a6f39c..083bc579b1af8 100644 --- a/libc/src/unistd/linux/CMakeLists.txt +++ b/libc/src/unistd/linux/CMakeLists.txt @@ -205,8 +205,6 @@ add_entrypoint_object( libc.include.sys_utsname libc.src.__support.OSUtil.osutil libc.src.errno.errno - libc.src.string.strlen - libc.src.string.strncpy ) add_entrypoint_object( From 0e569491f958853109cad2bcd19df6084b79f516 Mon Sep 17 00:00:00 2001 From: ZakyHermawan Date: Wed, 17 Sep 2025 12:38:05 +0700 Subject: [PATCH 5/9] fix clang-format Signed-off-by: ZakyHermawan --- libc/src/unistd/linux/gethostname.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libc/src/unistd/linux/gethostname.cpp b/libc/src/unistd/linux/gethostname.cpp index 7408b5f89b5ce..edfa3693b54f5 100644 --- a/libc/src/unistd/linux/gethostname.cpp +++ b/libc/src/unistd/linux/gethostname.cpp @@ -30,7 +30,8 @@ LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t size)) { return -1; } - // Because there is no SYS_gethostname syscall, we use uname to get the hostname. + // Because there is no SYS_gethostname syscall, we use uname to get the + // hostname. struct utsname unameData; int ret = LIBC_NAMESPACE::syscall_impl(SYS_uname, &unameData); if (ret < 0) { From aeb9ebe0190f4e0e5ac0db0c29b6a3539322daf2 Mon Sep 17 00:00:00 2001 From: ZakyHermawan Date: Wed, 17 Sep 2025 17:10:34 +0700 Subject: [PATCH 6/9] fix error caused by errno update Signed-off-by: ZakyHermawan --- libc/src/unistd/linux/gethostname.cpp | 3 +-- libc/test/src/unistd/CMakeLists.txt | 1 + libc/test/src/unistd/gethostname_test.cpp | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libc/src/unistd/linux/gethostname.cpp b/libc/src/unistd/linux/gethostname.cpp index edfa3693b54f5..f4d5b01060fd8 100644 --- a/libc/src/unistd/linux/gethostname.cpp +++ b/libc/src/unistd/linux/gethostname.cpp @@ -12,8 +12,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" #include "src/__support/macros/config.h" - -#include "src/errno/libc_errno.h" +#include "src/__support/libc_errno.h" #include "src/string/string_utils.h" #include // For syscall numbers. diff --git a/libc/test/src/unistd/CMakeLists.txt b/libc/test/src/unistd/CMakeLists.txt index c92d5e8e9db2b..6630a7ef15e53 100644 --- a/libc/test/src/unistd/CMakeLists.txt +++ b/libc/test/src/unistd/CMakeLists.txt @@ -417,6 +417,7 @@ add_libc_unittest( DEPENDS libc.src.unistd.gethostname libc.src.errno.errno + libc.test.UnitTest.ErrnoCheckingTest ) add_libc_unittest( diff --git a/libc/test/src/unistd/gethostname_test.cpp b/libc/test/src/unistd/gethostname_test.cpp index 3becf748fb6c0..a0e57ff0df333 100644 --- a/libc/test/src/unistd/gethostname_test.cpp +++ b/libc/test/src/unistd/gethostname_test.cpp @@ -6,10 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "src/errno/libc_errno.h" #include "src/unistd/gethostname.h" + +#include "test/UnitTest/ErrnoCheckingTest.h" #include "test/UnitTest/Test.h" +using LlvmLibcGetHostNameTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest; + TEST(LlvmLibcGetHostNameTest, GetCurrHostName) { char hostbuffer[1024]; int ret = LIBC_NAMESPACE::gethostname(hostbuffer, sizeof(hostbuffer)); From 9e141d513e924c22a54091b24a885d6169bae67f Mon Sep 17 00:00:00 2001 From: ZakyHermawan Date: Wed, 17 Sep 2025 17:18:31 +0700 Subject: [PATCH 7/9] fix formatting Signed-off-by: ZakyHermawan --- libc/src/unistd/linux/gethostname.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/src/unistd/linux/gethostname.cpp b/libc/src/unistd/linux/gethostname.cpp index f4d5b01060fd8..31f9fc4bba06d 100644 --- a/libc/src/unistd/linux/gethostname.cpp +++ b/libc/src/unistd/linux/gethostname.cpp @@ -11,8 +11,8 @@ #include "hdr/types/size_t.h" #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include "src/__support/macros/config.h" #include "src/__support/libc_errno.h" +#include "src/__support/macros/config.h" #include "src/string/string_utils.h" #include // For syscall numbers. From 32f3fc70bd0c751e2ef7a57fe866f9baaced2a35 Mon Sep 17 00:00:00 2001 From: ZakyHermawan Date: Wed, 17 Sep 2025 22:33:59 +0700 Subject: [PATCH 8/9] remove unnecessary includes Signed-off-by: ZakyHermawan --- libc/src/unistd/gethostname.h | 1 - libc/src/unistd/linux/gethostname.cpp | 2 -- 2 files changed, 3 deletions(-) diff --git a/libc/src/unistd/gethostname.h b/libc/src/unistd/gethostname.h index ef1b2d5381de6..cf67bdbd5c320 100644 --- a/libc/src/unistd/gethostname.h +++ b/libc/src/unistd/gethostname.h @@ -10,7 +10,6 @@ #define LLVM_LIBC_SRC_UNISTD_GETHOSTNAME_H #include "hdr/types/size_t.h" -#include "hdr/unistd_macros.h" #include "src/__support/macros/config.h" namespace LIBC_NAMESPACE_DECL { diff --git a/libc/src/unistd/linux/gethostname.cpp b/libc/src/unistd/linux/gethostname.cpp index 31f9fc4bba06d..570b1b33d30dd 100644 --- a/libc/src/unistd/linux/gethostname.cpp +++ b/libc/src/unistd/linux/gethostname.cpp @@ -18,8 +18,6 @@ #include // For syscall numbers. #include -#include - namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t size)) { From fb720b0a4a4ee21d63b06f164ebb9a620aa85645 Mon Sep 17 00:00:00 2001 From: ZakyHermawan Date: Tue, 23 Sep 2025 11:45:02 +0700 Subject: [PATCH 9/9] [NFC] remove unnecessary struct keyword Signed-off-by: ZakyHermawan --- libc/src/unistd/linux/gethostname.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/src/unistd/linux/gethostname.cpp b/libc/src/unistd/linux/gethostname.cpp index 570b1b33d30dd..60a12a4d6f8ea 100644 --- a/libc/src/unistd/linux/gethostname.cpp +++ b/libc/src/unistd/linux/gethostname.cpp @@ -29,7 +29,7 @@ LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t size)) { // Because there is no SYS_gethostname syscall, we use uname to get the // hostname. - struct utsname unameData; + utsname unameData; int ret = LIBC_NAMESPACE::syscall_impl(SYS_uname, &unameData); if (ret < 0) { libc_errno = static_cast(-ret);