[hackers] [slstatus] uptime: Separate function for readbility || Aaron Marcher

From: <git_AT_suckless.org>
Date: Sun, 29 Apr 2018 20:06:53 +0200 (CEST)

commit 273d3db573e55e5160c0697afbbb3c29781e961e
Author: Aaron Marcher <me_AT_drkhsh.at>
AuthorDate: Sun Apr 29 20:07:09 2018 +0200
Commit: Aaron Marcher <me_AT_drkhsh.at>
CommitDate: Sun Apr 29 20:07:09 2018 +0200

    uptime: Separate function for readbility

diff --git a/components/uptime.c b/components/uptime.c
index a3082f2..debe4cb 100644
--- a/components/uptime.c
+++ b/components/uptime.c
_AT_@ -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;
_AT_@ -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
Received on Sun Apr 29 2018 - 20:06:53 CEST

This archive was generated by hypermail 2.3.0 : Sun Apr 29 2018 - 20:12:42 CEST