From 00dbac9d16c08f618d84db9e04c4083f0688167d Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Sat, 27 Nov 2021 22:12:29 +0100 Subject: [PATCH] date: Port to LibMain :^) --- Userland/Utilities/CMakeLists.txt | 1 + Userland/Utilities/date.cpp | 18 ++++++------------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 612747cbf10..12e52d4b651 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -77,6 +77,7 @@ target_link_libraries(cpp-lexer LibMain) target_link_libraries(cpp-parser LibMain) target_link_libraries(cpp-preprocessor LibMain) target_link_libraries(cut LibMain) +target_link_libraries(date LibMain) target_link_libraries(diff LibDiff) target_link_libraries(disasm LibX86) target_link_libraries(dmesg LibMain) diff --git a/Userland/Utilities/date.cpp b/Userland/Utilities/date.cpp index 965f70ae4ef..1298a9ed763 100644 --- a/Userland/Utilities/date.cpp +++ b/Userland/Utilities/date.cpp @@ -7,16 +7,13 @@ #include #include #include -#include +#include +#include #include -#include -int main(int argc, char** argv) +ErrorOr serenity_main(Main::Arguments arguments) { - if (pledge("stdio settime", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(Core::System::pledge("stdio settime", nullptr)); bool print_unix_date = false; bool print_iso_8601 = false; @@ -30,7 +27,7 @@ int main(int argc, char** argv) args_parser.add_option(print_iso_8601, "Print date in ISO 8601 format", "iso-8601", 'i'); args_parser.add_option(print_rfc_3339, "Print date in RFC 3339 format", "rfc-3339", 'r'); args_parser.add_option(print_rfc_5322, "Print date in RFC 5322 format", "rfc-5322", 'R'); - args_parser.parse(argc, argv); + args_parser.parse(arguments); if (set_date != nullptr) { auto number = String(set_date).to_uint(); @@ -41,10 +38,7 @@ int main(int argc, char** argv) } timespec ts = { number.value(), 0 }; - if (clock_settime(CLOCK_REALTIME, &ts) < 0) { - perror("clock_settime"); - return 1; - } + TRY(Core::System::clock_settime(CLOCK_REALTIME, &ts)); return 0; }