2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2021-05-31 17:43:25 +03:00
|
|
|
#include <AK/Format.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
|
|
|
#include <stdio.h>
|
2020-02-18 15:18:33 +03:00
|
|
|
#include <unistd.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
|
|
|
|
2019-04-14 16:19:45 +03:00
|
|
|
FILE* fp = fopen("/proc/uptime", "r");
|
|
|
|
if (!fp) {
|
|
|
|
perror("fopen(/proc/uptime)");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-01-02 11:49:26 +03:00
|
|
|
TRY(Core::System::pledge("stdio"));
|
2020-02-18 15:18:33 +03:00
|
|
|
|
2019-04-14 16:19:45 +03:00
|
|
|
char buffer[BUFSIZ];
|
|
|
|
auto* p = fgets(buffer, sizeof(buffer), fp);
|
|
|
|
if (!p) {
|
|
|
|
perror("fgets");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned seconds;
|
|
|
|
sscanf(buffer, "%u", &seconds);
|
|
|
|
|
2021-05-31 17:43:25 +03:00
|
|
|
out("Up ");
|
2019-06-07 12:49:31 +03:00
|
|
|
|
2019-04-14 20:10:24 +03:00
|
|
|
if (seconds / 86400 > 0) {
|
2021-05-31 17:43:25 +03:00
|
|
|
out("{} day{}, ", seconds / 86400, (seconds / 86400) == 1 ? "" : "s");
|
2019-04-14 20:10:24 +03:00
|
|
|
seconds %= 86400;
|
|
|
|
}
|
2019-06-07 12:49:31 +03:00
|
|
|
|
2019-04-14 20:10:24 +03:00
|
|
|
if (seconds / 3600 > 0) {
|
2021-05-31 17:43:25 +03:00
|
|
|
out("{} hour{}, ", seconds / 3600, (seconds / 3600) == 1 ? "" : "s");
|
2019-04-14 20:10:24 +03:00
|
|
|
seconds %= 3600;
|
|
|
|
}
|
2019-06-07 12:49:31 +03:00
|
|
|
|
2019-04-14 20:10:24 +03:00
|
|
|
if (seconds / 60 > 0) {
|
2021-05-31 17:43:25 +03:00
|
|
|
out("{} minute{}, ", seconds / 60, (seconds / 60) == 1 ? "" : "s");
|
2019-04-14 20:10:24 +03:00
|
|
|
seconds %= 60;
|
|
|
|
}
|
2019-06-07 12:49:31 +03:00
|
|
|
|
2021-05-31 17:43:25 +03:00
|
|
|
out("{} second{}", seconds, seconds == 1 ? "" : "s");
|
|
|
|
outln();
|
2019-04-14 16:19:45 +03:00
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|