From f698a01020dc1cbcd316f2e69b3dd4662d054170 Mon Sep 17 00:00:00 2001 From: TheDarkBug Date: Sat, 24 Jul 2021 12:27:38 +0200 Subject: [PATCH] Added uptime for freebsd --- uwufetch.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 999d4f0..51f17bb 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -19,7 +19,7 @@ #include #include #include -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__FREEBSD__) #include #include #else @@ -295,6 +295,21 @@ int uptime_mac() } #endif +#ifdef __FREEBSD__ +int uptime_freebsd() +{ + int boot_time = 0; + static int request[2] = { CTL_KERN, KERN_BOOTTIME }; + struct timeval result; + size_t result_len = sizeof result; + + if (sysctl (request, 2, &result, &result_len, NULL, 0) >= 0) + boot_time = result.tv_sec; + int time_now = time (NULL); + return time_now - boot_time; +} +#endif + void print_info() { // store sys info in the sys again @@ -347,7 +362,9 @@ void print_info() #ifdef __APPLE__ uptime = uptime_mac(); #else -#ifndef __FREEBSD__ +#ifdef __FREEBSD__ + uptime = uptime_freebsd(); +#else uptime = sys.uptime; #endif #endif