X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/46c4540dd2f6181e77b0800a4e007d78d0162487..ec5c35ec9f23254f09e734d0c1880559774dfa52:/components/swap.c?ds=sidebyside diff --git a/components/swap.c b/components/swap.c index c005691..c697d61 100644 --- a/components/swap.c +++ b/components/swap.c @@ -48,7 +48,7 @@ } sscanf(match, "SwapFree: %ld kB\n", &free); - return fmt_human_2(free * 1024, "B"); + return fmt_human_2(free * 1024); } const char * @@ -76,7 +76,11 @@ } sscanf(match, "SwapFree: %ld kB\n", &free); - return bprintf("%d%%", 100 * (total - free - cached) / total); + if (total == 0) { + return NULL; + } + + return bprintf("%d", 100 * (total - free - cached) / total); } const char * @@ -94,7 +98,7 @@ } sscanf(match, "SwapTotal: %ld kB\n", &total); - return fmt_human_2(total * 1024, "B"); + return fmt_human_2(total * 1024); } const char * @@ -122,7 +126,7 @@ } sscanf(match, "SwapFree: %ld kB\n", &free); - return fmt_human_2((total - free - cached) * 1024, "B"); + return fmt_human_2((total - free - cached) * 1024); } #elif defined(__OpenBSD__) #include @@ -174,7 +178,7 @@ getstats(&total, &used); - return fmt_human_2((total - used) * 1024, "B"); + return fmt_human_2((total - used) * 1024); } const char * @@ -184,7 +188,11 @@ getstats(&total, &used); - return bprintf("%d%%", 100 * used / total); + if (total == 0) { + return NULL; + } + + return bprintf("%d", 100 * used / total); } const char * @@ -194,7 +202,7 @@ getstats(&total, &used); - return fmt_human_2(total * 1024, "B"); + return fmt_human_2(total * 1024); } const char * @@ -204,6 +212,6 @@ getstats(&total, &used); - return fmt_human_2(used * 1024, "B"); + return fmt_human_2(used * 1024); } #endif