X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/ec5c35ec9f23254f09e734d0c1880559774dfa52..7fe240856eef7b56d8ca0b57fd5642dbdc5b89b1:/components/ram.c diff --git a/components/ram.c b/components/ram.c index f653156..0333b3b 100644 --- a/components/ram.c +++ b/components/ram.c @@ -17,7 +17,7 @@ return NULL; } - return fmt_human_2(free * 1024); + return fmt_human(free * 1024, 1024); } const char * @@ -48,7 +48,7 @@ return NULL; } - return fmt_human_2(total * 1024); + return fmt_human(total * 1024, 1024); } const char * @@ -65,7 +65,8 @@ return NULL; } - return fmt_human_2((total - free - buffers - cached) * 1024); + return fmt_human((total - free - buffers - cached) * 1024, + 1024); } #elif defined(__OpenBSD__) #include @@ -74,7 +75,7 @@ #include #define LOG1024 10 - #define pagetok(size, pageshift) ((size) << (pageshift - LOG1024)) + #define pagetok(size, pageshift) (size_t)(size << (pageshift - LOG1024)) inline int load_uvmexp(struct uvmexp *uvmexp) @@ -84,7 +85,11 @@ size = sizeof(*uvmexp); - return sysctl(uvmexp_mib, 2, uvmexp, &size, NULL, 0) >= 0 ? 1 : 0; + if (sysctl(uvmexp_mib, 2, uvmexp, &size, NULL, 0) >= 0) { + return 1; + } + + return 0; } const char * @@ -95,8 +100,8 @@ if (load_uvmexp(&uvmexp)) { free_pages = uvmexp.npages - uvmexp.active; - return fmt_human_2(pagetok(free_pages, - uvmexp.pageshift) * 1024); + return fmt_human(pagetok(free_pages, uvmexp.pageshift) * + 1024, 1024); } return NULL; @@ -122,8 +127,9 @@ struct uvmexp uvmexp; if (load_uvmexp(&uvmexp)) { - return fmt_human_2(pagetok(uvmexp.npages, - uvmexp.pageshift) * 1024); + return fmt_human(pagetok(uvmexp.npages, + uvmexp.pageshift) * 1024, + 1024); } return NULL; @@ -135,8 +141,9 @@ struct uvmexp uvmexp; if (load_uvmexp(&uvmexp)) { - return fmt_human_2(pagetok(uvmexp.active, - uvmexp.pageshift) * 1024); + return fmt_human(pagetok(uvmexp.active, + uvmexp.pageshift) * 1024, + 1024); } return NULL;