From e2b5c1bfdd31f2914a7ecb897eb65a2dbe3c17c4 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 30 Oct 2022 09:09:03 +0100 Subject: [PATCH] uptime: Use clock_gettime instead of reading from /dev/uptime --- apps/src/uptime.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/apps/src/uptime.c b/apps/src/uptime.c index ee6313d5..4a5a652e 100644 --- a/apps/src/uptime.c +++ b/apps/src/uptime.c @@ -1,27 +1,10 @@ #include -#include +#include int main() { - FILE* fp = fopen("/dev/uptime", "r"); - if (!fp) - { - perror("fopen"); - return 1; - } + struct timespec tp; + clock_gettime(CLOCK_MONOTONIC, &tp); // On Luna, CLOCK_MONOTONIC starts at boot. - char buf[BUFSIZ]; - fgets(buf, sizeof(buf), fp); - - if (ferror(fp)) - { - perror("fgets"); - return 1; - } - - long ms_uptime = atol(buf); - - printf("up for %ld seconds\n", ms_uptime / 1000); - - fclose(fp); + printf("up for %ld seconds\n", tp.tv_sec); } \ No newline at end of file