diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 86b6e69a80..b6051d0851 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Andreas Kling + * Copyright (c) 2021, Kenneth Myhra * * SPDX-License-Identifier: BSD-2-Clause */ @@ -195,4 +196,13 @@ ErrorOr ptsname(int fd) return String(name); } +ErrorOr gethostname() +{ + char hostname[256]; + int rc = ::gethostname(hostname, sizeof(hostname)); + if (rc < 0) + return Error::from_syscall("gethostname"sv, -errno); + return String(&hostname[0]); +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 6345c150bf..d5e39d67ed 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -32,5 +32,6 @@ ErrorOr write(int fd, void const* data, size_t data_size); ErrorOr kill(pid_t, int signal); ErrorOr dup2(int source_fd, int destination_fd); ErrorOr ptsname(int fd); +ErrorOr gethostname(); }