diff options
author | Aaron Marcher <me@drkhsh.at> | 2018-04-29 20:07:09 +0200 |
---|---|---|
committer | Aaron Marcher <me@drkhsh.at> | 2018-04-29 20:07:09 +0200 |
commit | 273d3db573e55e5160c0697afbbb3c29781e961e (patch) | |
tree | eb4a2a88affc79e1c3b94e8ee2449a6731a60052 /components/uptime.c | |
parent | 09950055baa8ef17ba3ccee8bbe391de3110cc6f (diff) |
uptime: Separate function for readbility
Diffstat (limited to 'components/uptime.c')
-rw-r--r-- | components/uptime.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/components/uptime.c b/components/uptime.c index a3082f2..debe4cb 100644 --- a/components/uptime.c +++ b/components/uptime.c @@ -11,18 +11,31 @@ #include "../util.h" +#if defined(__linux__) const char * uptime(void) { int h; int m; int uptime = 0; -#if defined(__linux__) struct sysinfo info; sysinfo(&info); uptime = info.uptime; + + h = uptime / 3600; + m = (uptime - h * 3600) / 60; + + return bprintf("%dh %dm", h, m); +} #elif defined(__OpenBSD__) +const char * +uptime(void) +{ + int h; + int m; + int uptime = 0; + int mib[2]; size_t size; time_t now; @@ -41,9 +54,10 @@ uptime(void) fprintf(stderr, "sysctl 'KERN_BOOTTIME': %s\n", strerror(errno)); return NULL; } -#endif + h = uptime / 3600; m = (uptime - h * 3600) / 60; return bprintf("%dh %dm", h, m); } +#endif |