diff options
author | Lucas CHOLLET <lucas.chollet@free.fr> | 2022-01-13 23:15:25 +0100 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2022-01-14 19:42:19 +0200 |
commit | 8bc1a9e946b60932db83d451c20b7ae2ada82ffe (patch) | |
tree | 33a32cdce46ff7dac95a317da21e944fa00e1802 /Userland/Utilities | |
parent | b3b40ae1fad25e04493836259fc87ef91f67aa8b (diff) | |
download | serenity-8bc1a9e946b60932db83d451c20b7ae2ada82ffe.zip |
hostname: Port to LibMain
Diffstat (limited to 'Userland/Utilities')
-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; } |