diff options
author | Sascha Hauer <sha@octopus.labnet.pengutronix.de> | 2007-09-26 15:23:46 +0200 |
---|---|---|
committer | Sascha Hauer <sha@octopus.labnet.pengutronix.de> | 2007-09-26 15:23:46 +0200 |
commit | 326e4bddc3d36a2afc2781e3018e2649d2be0680 (patch) | |
tree | 73d5eb3166f160af6a912ec8bed0616ed5ed050e /lib | |
parent | 5efc6836b7318b2bb442b1584d9371d2ea2df6d9 (diff) | |
download | barebox-326e4bddc3d36a2afc2781e3018e2649d2be0680.tar.gz barebox-326e4bddc3d36a2afc2781e3018e2649d2be0680.tar.xz |
print_size() -> size_human_readable()
return a pointer to a human readable string rather than printingit directly
Diffstat (limited to 'lib')
-rw-r--r-- | lib/display_options.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/display_options.c b/lib/display_options.c index 6b84145734..5d92403272 100644 --- a/lib/display_options.c +++ b/lib/display_options.c @@ -24,14 +24,16 @@ #include <common.h> /* - * print sizes as "xxx kB", "xxx.y kB", "xxx MB" or "xxx.y MB" as needed; - * allow for optional trailing string (like "\n") + * return a pointer to a string containing the size + * as "xxx kB", "xxx.y kB", "xxx MB" or "xxx.y MB" as needed; */ -void print_size (ulong size, const char *s) +char *size_human_readable(ulong size) { + static char buf[20]; ulong m, n; ulong d = 1 << 20; /* 1 MB */ char c = 'M'; + char *ptr = buf; if (size < d) { /* print in kB */ c = 'k'; @@ -47,9 +49,12 @@ void print_size (ulong size, const char *s) n += 1; } - printf ("%2ld", n); + ptr += sprintf(buf, "%2ld", n); if (m) { - printf (".%ld", m); + ptr += sprintf (ptr,".%ld", m); } - printf (" %cB%s", c, s); + sprintf(ptr, " %cB", c); + + return buf; } + |