mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-06 05:04:17 +01:00
23 lines
573 B
C
23 lines
573 B
C
#include "uptime.h"
|
|
#include "common/time.h"
|
|
|
|
#include <sys/sysctl.h>
|
|
#include <sys/time.h>
|
|
|
|
const char* ffDetectUptime(FFUptimeResult* result)
|
|
{
|
|
struct timeval bootTime;
|
|
size_t bootTimeSize = sizeof(bootTime);
|
|
if(sysctl(
|
|
(int[]) {CTL_KERN, KERN_BOOTTIME}, 2,
|
|
&bootTime, &bootTimeSize,
|
|
NULL, 0
|
|
) != 0)
|
|
return "sysctl({CTL_KERN, KERN_BOOTTIME}) failed";
|
|
|
|
result->bootTime = (uint64_t) bootTime.tv_sec * 1000 + (uint64_t) bootTime.tv_usec / 1000;
|
|
result->uptime = ffTimeGetNow() - result->bootTime;
|
|
|
|
return NULL;
|
|
}
|