aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-11-05 00:44:39 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-11-05 00:44:39 +0000
commitaae0311356b4458e3a62fb19af656e00323e3bf1 (patch)
tree95ef467494c3178ffb308b95f8743886d9c9a5ae /miscutils
parent459e4d6cf77940977a064edab60c7162731554fb (diff)
downloadbusybox-aae0311356b4458e3a62fb19af656e00323e3bf1.tar.gz
smart_ulltoa5: make available in libbb
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/nmeter.c36
1 files changed, 1 insertions, 35 deletions
diff --git a/miscutils/nmeter.c b/miscutils/nmeter.c
index d71bd6add..326d7b85f 100644
--- a/miscutils/nmeter.c
+++ b/miscutils/nmeter.c
@@ -214,42 +214,8 @@ static int rdval_diskstats(const char* p, ullong *vec)
static void scale(ullong ul)
{
- char *fmt;
char buf[5];
- char c;
- unsigned v,idx = 0;
- ul *= 10;
- if (ul > 9999*10) { // do not scale if 9999 or less
- while (ul >= 10000) {
- ul /= 1024;
- idx++;
- }
- }
- v = ul; // ullong divisions are expensive, avoid them
-
- fmt = " 123456789";
- if (!idx) { // 9999 or less: use 1234 format
- c = buf[0] = " 123456789"[v/10000];
- if (c!=' ') fmt = "0123456789";
- c = buf[1] = fmt[v/1000%10];
- if (c!=' ') fmt = "0123456789";
- buf[2] = fmt[v/100%10];
- buf[3] = "0123456789"[v/10%10];
- } else {
- if (v>=10*10) { // scaled value is >=10: use 123M format
- c = buf[0] = " 123456789"[v/1000];
- if (c!=' ') fmt = "0123456789";
- buf[1] = fmt[v/100%10];
- buf[2] = "0123456789"[v/10%10];
- } else { // scaled value is <10: use 1.2M format
- buf[0] = "0123456789"[v/10];
- buf[1] = '.';
- buf[2] = "0123456789"[v%10];
- }
- // see http://en.wikipedia.org/wiki/Tera
- buf[3] = " kMGTPEZY"[idx];
- }
- buf[4] = '\0';
+ smart_ulltoa5(ul, buf);
put(buf);
}