From 89539c200bf93d53ee9b91b521c09bd4607e01d0 Mon Sep 17 00:00:00 2001 From: davidovski Date: Wed, 16 Feb 2022 23:22:36 +0000 Subject: added human formatting for hbar --- src/hbar.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'src/hbar.c') diff --git a/src/hbar.c b/src/hbar.c index e301fb4..17840d8 100644 --- a/src/hbar.c +++ b/src/hbar.c @@ -20,6 +20,21 @@ #define SAVE_POS "\033[s" #define LOAD_POS "\033[u" +static void human_format(int bytes, char *output) { + char *suffix[] = {"B", "KB", "MB", "GB", "TB"}; + char length = sizeof(suffix) / sizeof(suffix[0]); + + int i = 0; + double dblBytes = bytes; + + if (bytes > 1024) { + for (i = 0; (bytes / 1024) > 0 && i