X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/46c4540dd2f6181e77b0800a4e007d78d0162487..4bd234c7ef7224117a6e50eda4ce3184338daab1:/components/swap.c?ds=sidebyside diff --git a/components/swap.c b/components/swap.c index c005691..f5db667 100644 --- a/components/swap.c +++ b/components/swap.c @@ -76,6 +76,10 @@ } sscanf(match, "SwapFree: %ld kB\n", &free); + if (total == 0) { + return NULL; + } + return bprintf("%d%%", 100 * (total - free - cached) / total); } @@ -184,6 +188,10 @@ getstats(&total, &used); + if (total == 0) { + return NULL; + } + return bprintf("%d%%", 100 * used / total); }