diff options
-rw-r--r-- | Userland/Utilities/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Utilities/hostname.cpp | 20 |
2 files changed, 7 insertions, 14 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index f8ec89ce7c..d50212c4e2 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -108,6 +108,7 @@ target_link_libraries(gzip LibCompress LibMain) target_link_libraries(head LibMain) target_link_libraries(hexdump LibMain) target_link_libraries(host LibMain) +target_link_libraries(hostname LibMain) target_link_libraries(id LibMain) target_link_libraries(ini LibMain) target_link_libraries(jp LibMain) diff --git a/Userland/Utilities/hostname.cpp b/Userland/Utilities/hostname.cpp index b620242f50..b99713638f 100644 --- a/Userland/Utilities/hostname.cpp +++ b/Userland/Utilities/hostname.cpp @@ -5,37 +5,29 @@ */ #include <LibCore/ArgsParser.h> +#include <LibCore/System.h> +#include <LibMain/Main.h> #include <limits.h> #include <stdio.h> #include <string.h> #include <unistd.h> -int main(int argc, char** argv) +ErrorOr<int> serenity_main(Main::Arguments args) { const char* hostname = nullptr; Core::ArgsParser args_parser; args_parser.add_positional_argument(hostname, "Hostname to set", "hostname", Core::ArgsParser::Required::No); - args_parser.parse(argc, argv); + args_parser.parse(args); if (!hostname) { - char buffer[HOST_NAME_MAX]; - int rc = gethostname(buffer, sizeof(buffer)); - if (rc < 0) { - perror("gethostname"); - return 1; - } - outln("{}", buffer); + outln("{}", TRY(Core::System::gethostname())); } else { if (strlen(hostname) >= HOST_NAME_MAX) { warnln("Hostname must be less than {} characters", HOST_NAME_MAX); return 1; } - int rc = sethostname(hostname, strlen(hostname)); - if (rc < 0) { - perror("sethostname"); - return 1; - } + TRY(Core::System::sethostname(hostname)); } return 0; } |