[hackers] [slstatus] Implement fmt_scaled for ram_* functions || Aaron Marcher
commit d0c68989cd9f42f2b79da3a2ebe9d4765b28bfc1
Author: Aaron Marcher <me_AT_drkhsh.at>
AuthorDate: Fri May 18 23:38:59 2018 +0200
Commit: Aaron Marcher <me_AT_drkhsh.at>
CommitDate: Fri May 18 23:38:59 2018 +0200
Implement fmt_scaled for ram_* functions
diff --git a/components/ram.c b/components/ram.c
index f451601..8f96b04 100644
--- a/components/ram.c
+++ b/components/ram.c
_AT_@ -14,7 +14,7 @@
"MemFree: %ld kB\n"
"MemAvailable: %ld kB\n",
&free, &free, &free) == 3) ?
- bprintf("%f", (float)free / 1024 / 1024) : NULL;
+ fmt_scaled(free * 1024) : NULL;
}
const char *
_AT_@ -39,7 +39,7 @@
long total;
return (pscanf("/proc/meminfo", "MemTotal: %ld kB\n", &total) == 1) ?
- bprintf("%f", (float)total / 1024 / 1024) : NULL;
+ fmt_scaled(total * 1024) : NULL;
}
const char *
_AT_@ -53,9 +53,7 @@
"MemAvailable: %ld kB\nBuffers: %ld kB\n"
"Cached: %ld kB\n",
&total, &free, &buffers, &buffers, &cached) == 5) ?
- bprintf("%f", (float)(total - free - buffers - cached) /
- 1024 / 1024) :
- NULL;
+ fmt_scaled((total - free - buffers - cached) * 1024) : NULL;
}
#elif defined(__OpenBSD__)
#include <stdlib.h>
_AT_@ -81,13 +79,11 @@
ram_free(void)
{
struct uvmexp uvmexp;
- float free;
int free_pages;
if (load_uvmexp(&uvmexp)) {
free_pages = uvmexp.npages - uvmexp.active;
- free = (float)(pagetok(free_pages, uvmexp.pageshift)) / 1024 / 1024;
- return bprintf("%f", free);
+ return fmt_scaled(pagetok(free_pages, uvmexp.pageshift) * 1024);
}
return NULL;
_AT_@ -111,11 +107,9 @@
ram_total(void)
{
struct uvmexp uvmexp;
- float total;
if (load_uvmexp(&uvmexp)) {
- total = (float)(pagetok(uvmexp.npages, uvmexp.pageshift)) / 1024 / 1024;
- return bprintf("%f", total);
+ return fmt_scaled(pagetok(uvmexp.npages, uvmexp.pageshift) * 1024);
}
return NULL;
_AT_@ -125,11 +119,9 @@
ram_used(void)
{
struct uvmexp uvmexp;
- float used;
if (load_uvmexp(&uvmexp)) {
- used = (float)(pagetok(uvmexp.active, uvmexp.pageshift)) / 1024 / 1024;
- return bprintf("%f", used);
+ return fmt_scaled(pagetok(uvmexp.active, uvmexp.pageshift) * 1024);
}
return NULL;
Received on Fri May 18 2018 - 23:39:19 CEST
This archive was generated by hypermail 2.3.0
: Fri May 18 2018 - 23:48:30 CEST