From cc2ead813651399fcaf8b46dbbaf035261bfa006 Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Tue, 2 Oct 2012 23:01:57 +0200 Subject: [PATCH] Use util's format_size. --- src/tools/adcrush.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/tools/adcrush.c b/src/tools/adcrush.c index bc70747..fdc72ad 100644 --- a/src/tools/adcrush.c +++ b/src/tools/adcrush.c @@ -138,23 +138,6 @@ static void bot_output(struct ADC_client* client, int level, const char* format, } } -static const char* format_size(size_t bytes) -{ - static char buf[64]; - static const char* quant[] = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; - size_t b = bytes; - size_t factor = 0; - size_t divisor = 1; - while (b > 1024) - { - factor++; - b = (b >> 10); - divisor = (divisor << 10); - } - - snprintf(buf, sizeof(buf), "%.2f %s", (double) bytes / (double) divisor, quant[factor]); - return buf; -} static size_t get_wait_rand(size_t max) { @@ -438,8 +421,8 @@ void p_status() rx = stats_intermediate->rx / cfg_netstats_interval; tx = stats_intermediate->tx / cfg_netstats_interval; net_stats_reset(); - strcpy(rxbuf, format_size(rx)); - strcpy(txbuf, format_size(tx)); + format_size(rx, rxbuf, sizeof(rxbuf)); + format_size(tx, txbuf, sizeof(txbuf)); } n = blank;