diff options
author | Laslo Hunhold <dev@frign.de> | 2018-05-19 22:52:17 +0200 |
---|---|---|
committer | Aaron Marcher <me@drkhsh.at> | 2018-05-19 22:58:21 +0200 |
commit | 46c4540dd2f6181e77b0800a4e007d78d0162487 (patch) | |
tree | 7fcec772ef1dd3dbb8bdcaf30aa48c2fea1d096f /components/ram.c | |
parent | 74c4f4ebdae8a12fc95840954dde574692234b01 (diff) |
Implement fmt_human_2() and fmt_human_10()
These functions take the raw number and a unit and automatically
print it out "scaled down" to a proper SI-prefix, for powers of 2
and 10 respectively.
Apply them to the 2-power cases and keep the 10-power for a later
commit.
Diffstat (limited to 'components/ram.c')
-rw-r--r-- | components/ram.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/components/ram.c b/components/ram.c index 0eb2ea9..1c12aab 100644 --- a/components/ram.c +++ b/components/ram.c @@ -14,7 +14,7 @@ "MemFree: %ld kB\n" "MemAvailable: %ld kB\n", &free, &free, &free) == 3) ? - fmt_scaled(free * 1024) : NULL; + fmt_human_2(free * 1024, "B") : NULL; } const char * @@ -39,7 +39,7 @@ long total; return (pscanf("/proc/meminfo", "MemTotal: %ld kB\n", &total) == 1) ? - fmt_scaled(total * 1024) : NULL; + fmt_human_2(total * 1024, "B") : NULL; } const char * @@ -53,7 +53,7 @@ "MemAvailable: %ld kB\nBuffers: %ld kB\n" "Cached: %ld kB\n", &total, &free, &buffers, &buffers, &cached) == 5) ? - fmt_scaled((total - free - buffers - cached) * 1024) : NULL; + fmt_human_2((total - free - buffers - cached) * 1024, "B") : NULL; } #elif defined(__OpenBSD__) #include <stdlib.h> @@ -83,7 +83,7 @@ if (load_uvmexp(&uvmexp)) { free_pages = uvmexp.npages - uvmexp.active; - return fmt_scaled(pagetok(free_pages, uvmexp.pageshift) * 1024); + return fmt_human_2(pagetok(free_pages, uvmexp.pageshift) * 1024, "B"); } return NULL; @@ -109,7 +109,7 @@ struct uvmexp uvmexp; if (load_uvmexp(&uvmexp)) { - return fmt_scaled(pagetok(uvmexp.npages, uvmexp.pageshift) * 1024); + return fmt_human_2(pagetok(uvmexp.npages, uvmexp.pageshift) * 1024, "B"); } return NULL; @@ -121,7 +121,7 @@ struct uvmexp uvmexp; if (load_uvmexp(&uvmexp)) { - return fmt_scaled(pagetok(uvmexp.active, uvmexp.pageshift) * 1024); + return fmt_human_2(pagetok(uvmexp.active, uvmexp.pageshift) * 1024, "B"); } return NULL; |