2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-12-18 15:25:08 +03:00
|
|
|
* Copyright (c) 2022, Karol Kosek <krkk@serenityos.org>
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2022-12-18 15:25:08 +03:00
|
|
|
#include <AK/NumberFormat.h>
|
2023-02-09 05:02:46 +03:00
|
|
|
#include <LibCore/File.h>
|
2022-01-02 11:49:26 +03:00
|
|
|
#include <LibCore/System.h>
|
|
|
|
#include <LibMain/Main.h>
|
2019-04-14 16:19:45 +03:00
|
|
|
|
2022-01-02 11:49:26 +03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments)
|
2019-04-14 16:19:45 +03:00
|
|
|
{
|
2022-01-02 11:49:26 +03:00
|
|
|
TRY(Core::System::pledge("stdio rpath"));
|
2020-02-18 15:18:33 +03:00
|
|
|
|
2023-02-09 05:02:46 +03:00
|
|
|
auto file = TRY(Core::File::open("/sys/kernel/uptime"sv, Core::File::OpenMode::Read));
|
2019-04-14 16:19:45 +03:00
|
|
|
|
2022-01-02 11:49:26 +03:00
|
|
|
TRY(Core::System::pledge("stdio"));
|
2020-02-18 15:18:33 +03:00
|
|
|
|
2022-12-18 15:25:08 +03:00
|
|
|
Array<u8, BUFSIZ> buffer;
|
2023-02-25 00:38:01 +03:00
|
|
|
auto read_buffer = TRY(file->read_some(buffer));
|
2022-12-18 15:25:08 +03: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 16:19:45 +03:00
|
|
|
|
2022-12-18 15:25:08 +03:00
|
|
|
outln("Up {}", human_readable_time(seconds));
|
2019-04-14 16:19:45 +03:00
|
|
|
return 0;
|
|
|
|
}
|