From b3b40ae1fad25e04493836259fc87ef91f67aa8b Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Fri, 14 Jan 2022 10:20:29 +0100 Subject: [PATCH] LibCore: Add wrapper for sethostname --- Userland/Libraries/LibCore/System.cpp | 8 ++++++++ Userland/Libraries/LibCore/System.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index f29fb758ca..bbc1a08684 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -352,6 +352,14 @@ ErrorOr gethostname() return String(&hostname[0]); } +ErrorOr sethostname(StringView hostname) +{ + int rc = ::sethostname(hostname.characters_without_null_termination(), hostname.length()); + if (rc < 0) + return Error::from_syscall("sethostname"sv, -errno); + return {}; +} + ErrorOr getcwd() { auto* cwd = ::getcwd(nullptr, 0); diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 7cf6027d53..1ade033c6a 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -9,6 +9,7 @@ #pragma once #include +#include #include #include #include @@ -72,6 +73,7 @@ ErrorOr dup(int source_fd); ErrorOr dup2(int source_fd, int destination_fd); ErrorOr ptsname(int fd); ErrorOr gethostname(); +ErrorOr sethostname(StringView); ErrorOr getcwd(); ErrorOr ioctl(int fd, unsigned request, ...); ErrorOr tcgetattr(int fd);