Uptime: support Windows

This commit is contained in:
李通洲
2022-10-13 10:39:11 +08:00
parent d769fd32f0
commit 2689a20889
6 changed files with 55 additions and 23 deletions
+2 -23
View File
@@ -1,34 +1,13 @@
#include "fastfetch.h"
#include "common/printing.h"
#if __APPLE__
#include "time.h"
#include "sys/sysctl.h"
#endif
#include "detection/uptime/uptime.h"
#define FF_UPTIME_MODULE_NAME "Uptime"
#define FF_UPTIME_NUM_FORMAT_ARGS 4
void ffPrintUptime(FFinstance* instance)
{
uint64_t uptime;
#if FF_HAVE_SYSINFO_H
uptime = (uint64_t) instance->state.sysinfo.uptime;
#elif __APPLE__
struct timeval bootTime;
size_t bootTimeSize = sizeof(bootTime);
if(sysctl(
(int[]) {CTL_KERN, KERN_BOOTTIME}, 2,
&bootTime, &bootTimeSize,
NULL, 0
) == 0)
uptime = (uint64_t) difftime(time(NULL), bootTime.tv_sec);
else
uptime = 0;
#else
uptime = 0;
#endif
uint64_t uptime = ffDetectUptime(instance);
if(uptime == 0)
{