[hackers] [slstatus] Refactor ram.c || Aaron Marcher

From: <git_AT_suckless.org>
Date: Sun, 20 May 2018 00:42:20 +0200 (CEST)

commit c12b9cc50b5f476cd7b1de1dbd49e6282b1a042f
Author: Aaron Marcher <me_AT_drkhsh.at>
AuthorDate: Sun May 20 00:42:07 2018 +0200
Commit: Aaron Marcher <me_AT_drkhsh.at>
CommitDate: Sun May 20 00:42:07 2018 +0200

    Refactor ram.c

diff --git a/components/ram.c b/components/ram.c
index 1c12aab..7c0870c 100644
--- a/components/ram.c
+++ b/components/ram.c
_AT_@ -9,12 +9,15 @@
         {
                 long free;
 
- return (pscanf("/proc/meminfo",
- "MemTotal: %ld kB\n"
- "MemFree: %ld kB\n"
- "MemAvailable: %ld kB\n",
- &free, &free, &free) == 3) ?
- fmt_human_2(free * 1024, "B") : NULL;
+ if (pscanf("/proc/meminfo",
+ "MemTotal: %ld kB\n"
+ "MemFree: %ld kB\n"
+ "MemAvailable: %ld kB\n",
+ &free, &free, &free) != 3) {
+ return NULL;
+ }
+
+ return fmt_human_2(free * 1024, "B");
         }
 
         const char *
_AT_@ -22,15 +25,17 @@
         {
                 long total, free, buffers, cached;
 
- return (pscanf("/proc/meminfo",
- "MemTotal: %ld kB\n"
- "MemFree: %ld kB\n"
- "MemAvailable: %ld kB\nBuffers: %ld kB\n"
- "Cached: %ld kB\n",
- &total, &free, &buffers, &buffers, &cached) == 5) ?
- bprintf("%d%%", 100 * ((total - free) - (buffers + cached)) /
- total) :
- NULL;
+ if (pscanf("/proc/meminfo",
+ "MemTotal: %ld kB\n"
+ "MemFree: %ld kB\n"
+ "MemAvailable: %ld kB\nBuffers: %ld kB\n"
+ "Cached: %ld kB\n",
+ &total, &free, &buffers, &buffers, &cached) != 5) {
+ return NULL;
+ }
+
+ return bprintf("%d%%", 100 * ((total - free) -
+ (buffers + cached)) / total);
         }
 
         const char *
_AT_@ -38,8 +43,12 @@
         {
                 long total;
 
- return (pscanf("/proc/meminfo", "MemTotal: %ld kB\n", &total) == 1) ?
- fmt_human_2(total * 1024, "B") : NULL;
+ if (pscanf("/proc/meminfo", "MemTotal: %ld kB\n",
+ &total) != 1) {
+ return NULL;
+ }
+
+ return fmt_human_2(total * 1024, "B");
         }
 
         const char *
_AT_@ -47,13 +56,17 @@
         {
                 long total, free, buffers, cached;
 
- return (pscanf("/proc/meminfo",
- "MemTotal: %ld kB\n"
- "MemFree: %ld kB\n"
- "MemAvailable: %ld kB\nBuffers: %ld kB\n"
- "Cached: %ld kB\n",
- &total, &free, &buffers, &buffers, &cached) == 5) ?
- fmt_human_2((total - free - buffers - cached) * 1024, "B") : NULL;
+ if (pscanf("/proc/meminfo",
+ "MemTotal: %ld kB\n"
+ "MemFree: %ld kB\n"
+ "MemAvailable: %ld kB\nBuffers: %ld kB\n"
+ "Cached: %ld kB\n",
+ &total, &free, &buffers, &buffers, &cached) != 5) {
+ return NULL;
+ }
+
+ return fmt_human_2((total - free - buffers - cached) * 1024,
+ "B");
         }
 #elif defined(__OpenBSD__)
         #include <stdlib.h>
Received on Sun May 20 2018 - 00:42:20 CEST

This archive was generated by hypermail 2.3.0 : Sun May 20 2018 - 00:48:23 CEST