From bad9a70a48ff38f0d1e22fdedfcaa2241882a0bf Mon Sep 17 00:00:00 2001 From: Bert Date: Thu, 3 Feb 2011 14:32:02 +0100 Subject: Display filesize in window title --- util.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index c357a48..ac81190 100644 --- a/util.c +++ b/util.c @@ -66,3 +66,12 @@ void die(const char* fmt, ...) { cleanup(); exit(1); } + +void size_readable(float *size, const char **unit) { + const char *units[] = { "", "K", "M", "G" }; + int i; + + for (i = 0; i < LEN(units) && *size > 1024; ++i) + *size /= 1024; + *unit = units[MIN(i, LEN(units) - 1)]; +} -- cgit v1.2.3