summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Meta/Lagom/CMakeLists.txt2
-rw-r--r--Userland/Utilities/CMakeLists.txt1
-rw-r--r--Userland/Utilities/adjtime.cpp32
3 files changed, 13 insertions, 22 deletions
diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt
index 95e7aa9b78..a22b0396dd 100644
--- a/Meta/Lagom/CMakeLists.txt
+++ b/Meta/Lagom/CMakeLists.txt
@@ -474,7 +474,7 @@ if (BUILD_LAGOM)
# Lagom Utilities
add_executable(adjtime_lagom ../../Userland/Utilities/adjtime.cpp)
set_target_properties(adjtime_lagom PROPERTIES OUTPUT_NAME adjtime)
- target_link_libraries(adjtime_lagom LagomCore)
+ target_link_libraries(adjtime_lagom LagomCore LagomMain)
add_executable(disasm_lagom ../../Userland/Utilities/disasm.cpp)
set_target_properties(disasm_lagom PROPERTIES OUTPUT_NAME disasm)
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt
index 0e12b689ec..6127e5b4d3 100644
--- a/Userland/Utilities/CMakeLists.txt
+++ b/Userland/Utilities/CMakeLists.txt
@@ -52,6 +52,7 @@ foreach(CMD_SRC ${CMD_SOURCES})
endforeach()
target_link_libraries(abench LibAudio LibMain LibCore)
+target_link_libraries(adjtime LibMain)
target_link_libraries(allocate LibMain)
target_link_libraries(aplay LibAudio LibMain)
target_link_libraries(arp LibMain)
diff --git a/Userland/Utilities/adjtime.cpp b/Userland/Utilities/adjtime.cpp
index 0d2f60478f..ba56cf8be1 100644
--- a/Userland/Utilities/adjtime.cpp
+++ b/Userland/Utilities/adjtime.cpp
@@ -1,30 +1,29 @@
/*
* Copyright (c) 2020, Nico Weber <thakis@chromium.org>
+ * Copyright (c) 2022, Matthias Zimmerman <matthias291999@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/ArgsParser.h>
+#include <LibCore/System.h>
#include <math.h>
#include <sys/time.h>
#include <unistd.h>
-int main(int argc, char** argv)
+ErrorOr<int> serenity_main(Main::Arguments arguments)
{
#ifdef __serenity__
- if (pledge("stdio settime", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio settime"));
#endif
Core::ArgsParser args_parser;
- double delta = __builtin_nan("");
+ Optional<double> delta;
args_parser.add_option(delta, "Adjust system time by this many seconds", "set", 's', "delta_seconds");
- args_parser.parse(argc, argv);
+ args_parser.parse(arguments);
- if (!__builtin_isnan(delta)) {
- long delta_us = static_cast<long>(round(delta * 1'000'000));
+ if (delta.has_value()) {
+ long delta_us = static_cast<long>(round(*delta * 1'000'000));
timeval delta_timeval;
delta_timeval.tv_sec = delta_us / 1'000'000;
delta_timeval.tv_usec = delta_us % 1'000'000;
@@ -32,24 +31,15 @@ int main(int argc, char** argv)
delta_timeval.tv_sec--;
delta_timeval.tv_usec += 1'000'000;
}
- if (adjtime(&delta_timeval, nullptr) < 0) {
- perror("adjtime set");
- return 1;
- }
+ TRY(Core::System::adjtime(&delta_timeval, nullptr));
}
#ifdef __serenity__
- if (pledge("stdio", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio"));
#endif
timeval remaining_delta_timeval;
- if (adjtime(nullptr, &remaining_delta_timeval) < 0) {
- perror("adjtime get");
- return 1;
- }
+ TRY(Core::System::adjtime(nullptr, &remaining_delta_timeval));
double remaining_delta = remaining_delta_timeval.tv_sec + remaining_delta_timeval.tv_usec / 1'000'000.0;
outln("{}", remaining_delta);