all repos — slstatus @ 35219d39caa5ab5e0b1c9e6d4a1cbb29a388842e

my build of slstatus (tools.suckless.org/slstatus/)

Add fmt_scaled util function
Aaron Marcher me@drkhsh.at
Fri, 18 May 2018 23:14:10 +0200
commit

35219d39caa5ab5e0b1c9e6d4a1cbb29a388842e

parent

f3178199848911c8fb51b30e3993ae47120fcc6c

2 files changed, 17 insertions(+), 0 deletions(-)

jump to
M util.cutil.c

@@ -65,6 +65,22 @@

return buf; } +const char * +fmt_scaled(size_t bytes) +{ + unsigned int i; + float scaled; + const char *units[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", + "ZiB", "YiB" }; + + scaled = bytes; + for (i = 0; i < LEN(units) && scaled >= 1024; i++) { + scaled /= 1024.0; + } + + return bprintf("%.1f%s", scaled, units[i]); +} + int pscanf(const char *path, const char *fmt, ...) {
M util.hutil.h

@@ -9,4 +9,5 @@ void warn(const char *, ...);

void die(const char *, ...); const char *bprintf(const char *fmt, ...); +const char *fmt_scaled(size_t); int pscanf(const char *path, const char *fmt, ...);