[libc-commits] [libc] [libc][POSIX][unistd] Implement gethostname (PR #128142)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Fri Feb 21 12:41:03 PST 2025


================
@@ -0,0 +1,60 @@
+//===-- 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/errno/libc_errno.h"
+#include "src/string/strlen.h"
+#include "src/string/strncpy.h"
+
+#include <sys/syscall.h> // For syscall numbers.
+#include <sys/utsname.h>
+
+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.
----------------
michaelrj-google wrote:

we don't actually want to mimic glibc exactly. It's more important to match the standard, and make reasonable choices.

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


More information about the libc-commits mailing list