mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 10:52:08 +02:00
f4424b4204
the previous implementation was adding the elapsed time since boot to the current time instead of subtracting it
39 lines
949 B
C
39 lines
949 B
C
#include "uptime.h"
|
|
#include "common/time.h"
|
|
#include "common/io/io.h"
|
|
|
|
#include <inttypes.h>
|
|
|
|
const char* ffDetectUptime(FFUptimeResult* result)
|
|
{
|
|
#ifndef __ANDROID__ // cat: /proc/uptime: Permission denied
|
|
|
|
// #620
|
|
char buf[64];
|
|
ssize_t nRead = ffReadFileData("/proc/uptime", sizeof(buf) - 1, buf);
|
|
if(nRead > 0)
|
|
{
|
|
buf[nRead] = '\0';
|
|
|
|
char *err = NULL;
|
|
double sec = strtod(buf, &err);
|
|
if(err != buf)
|
|
{
|
|
result->uptime = (uint64_t) (sec * 1000);
|
|
result->bootTime = ffTimeGetNow() - result->uptime;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
struct timespec uptime;
|
|
if (clock_gettime(CLOCK_BOOTTIME, &uptime) != 0)
|
|
return "clock_gettime(CLOCK_BOOTTIME) failed";
|
|
|
|
result->uptime = (uint64_t) uptime.tv_sec * 1000 + (uint64_t) uptime.tv_nsec / 1000000;
|
|
result->bootTime = ffTimeGetNow() - result->uptime;
|
|
|
|
return NULL;
|
|
}
|