2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-12-18 12:25:08 +00:00
|
|
|
* Copyright (c) 2022, Karol Kosek <krkk@serenityos.org>
|
2020-01-18 08:38:21 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2022-12-18 12:25:08 +00:00
|
|
|
#include <AK/NumberFormat.h>
|
2023-02-09 02:02:46 +00:00
|
|
|
#include <LibCore/File.h>
|
2022-01-02 08:49:26 +00:00
|
|
|
#include <LibCore/System.h>
|
|
|
|
#include <LibMain/Main.h>
|
2019-04-14 13:19:45 +00:00
|
|
|
|
2022-01-02 08:49:26 +00:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments)
|
2019-04-14 13:19:45 +00:00
|
|
|
{
|
2022-01-02 08:49:26 +00:00
|
|
|
TRY(Core::System::pledge("stdio rpath"));
|
2020-02-18 12:18:33 +00:00
|
|
|
|
2023-02-09 02:02:46 +00:00
|
|
|
auto file = TRY(Core::File::open("/sys/kernel/uptime"sv, Core::File::OpenMode::Read));
|
2019-04-14 13:19:45 +00:00
|
|
|
|
2022-01-02 08:49:26 +00:00
|
|
|
TRY(Core::System::pledge("stdio"));
|
2020-02-18 12:18:33 +00:00
|
|
|
|
2022-12-18 12:25:08 +00:00
|
|
|
Array<u8, BUFSIZ> buffer;
|
2023-02-24 21:38:01 +00:00
|
|
|
auto read_buffer = TRY(file->read_some(buffer));
|
2022-12-18 12:25:08 +00:00
|
|
|
auto maybe_seconds = AK::StringUtils::convert_to_uint(StringView(read_buffer));
|
|
|
|
if (!maybe_seconds.has_value())
|
|
|
|
return Error::from_string_literal("Couldn't convert to number");
|
|
|
|
auto seconds = maybe_seconds.release_value();
|
2019-04-14 13:19:45 +00:00
|
|
|
|
2022-12-18 12:25:08 +00:00
|
|
|
outln("Up {}", human_readable_time(seconds));
|
2019-04-14 13:19:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|