date: Port to LibMain :^)

This commit is contained in:
Kenneth Myhra 2021-11-27 22:12:29 +01:00 committed by Brian Gianforcaro
parent 7b13f22f96
commit 00dbac9d16
Notes: sideshowbarker 2024-07-17 22:55:48 +09:00
2 changed files with 7 additions and 12 deletions

View file

@ -77,6 +77,7 @@ target_link_libraries(cpp-lexer LibMain)
target_link_libraries(cpp-parser LibMain) target_link_libraries(cpp-parser LibMain)
target_link_libraries(cpp-preprocessor LibMain) target_link_libraries(cpp-preprocessor LibMain)
target_link_libraries(cut LibMain) target_link_libraries(cut LibMain)
target_link_libraries(date LibMain)
target_link_libraries(diff LibDiff) target_link_libraries(diff LibDiff)
target_link_libraries(disasm LibX86) target_link_libraries(disasm LibX86)
target_link_libraries(dmesg LibMain) target_link_libraries(dmesg LibMain)

View file

@ -7,16 +7,13 @@
#include <AK/String.h> #include <AK/String.h>
#include <LibCore/ArgsParser.h> #include <LibCore/ArgsParser.h>
#include <LibCore/DateTime.h> #include <LibCore/DateTime.h>
#include <stdio.h> #include <LibCore/System.h>
#include <LibMain/Main.h>
#include <time.h> #include <time.h>
#include <unistd.h>
int main(int argc, char** argv) ErrorOr<int> serenity_main(Main::Arguments arguments)
{ {
if (pledge("stdio settime", nullptr) < 0) { TRY(Core::System::pledge("stdio settime", nullptr));
perror("pledge");
return 1;
}
bool print_unix_date = false; bool print_unix_date = false;
bool print_iso_8601 = 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_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_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.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) { if (set_date != nullptr) {
auto number = String(set_date).to_uint(); auto number = String(set_date).to_uint();
@ -41,10 +38,7 @@ int main(int argc, char** argv)
} }
timespec ts = { number.value(), 0 }; timespec ts = { number.value(), 0 };
if (clock_settime(CLOCK_REALTIME, &ts) < 0) { TRY(Core::System::clock_settime(CLOCK_REALTIME, &ts));
perror("clock_settime");
return 1;
}
return 0; return 0;
} }