uptime: Separate function for readbility

This commit is contained in:
Aaron Marcher 2018-04-29 20:07:09 +02:00
parent 09950055ba
commit 273d3db573

View file

@ -11,18 +11,31 @@
#include "../util.h" #include "../util.h"
#if defined(__linux__)
const char * const char *
uptime(void) uptime(void)
{ {
int h; int h;
int m; int m;
int uptime = 0; int uptime = 0;
#if defined(__linux__)
struct sysinfo info; struct sysinfo info;
sysinfo(&info); sysinfo(&info);
uptime = info.uptime; uptime = info.uptime;
h = uptime / 3600;
m = (uptime - h * 3600) / 60;
return bprintf("%dh %dm", h, m);
}
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__)
const char *
uptime(void)
{
int h;
int m;
int uptime = 0;
int mib[2]; int mib[2];
size_t size; size_t size;
time_t now; time_t now;
@ -41,9 +54,10 @@ uptime(void)
fprintf(stderr, "sysctl 'KERN_BOOTTIME': %s\n", strerror(errno)); fprintf(stderr, "sysctl 'KERN_BOOTTIME': %s\n", strerror(errno));
return NULL; return NULL;
} }
#endif
h = uptime / 3600; h = uptime / 3600;
m = (uptime - h * 3600) / 60; m = (uptime - h * 3600) / 60;
return bprintf("%dh %dm", h, m); return bprintf("%dh %dm", h, m);
} }
#endif