From 6062ac7c37c9290f1c4951d6b7bfc02ac3cadefe Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 5 May 2004 08:43:23 +0000 Subject: made the progress meter display not overflow even if _very_ large files are transfered. The maximum size we support now is 8 exabytes, which equals to 8192 petabytes... --- lib/progress.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/progress.c b/lib/progress.c index 51333aff1..98c101096 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -68,8 +68,10 @@ static void time2str(char *r, long t) static char *max5data(curl_off_t bytes, char *max5) { #define ONE_KILOBYTE 1024 -#define ONE_MEGABYTE (1024*1024) -#define ONE_GIGABYTE (1024*1024*1024) +#define ONE_MEGABYTE (1024* ONE_KILOBYTE) +#define ONE_GIGABYTE (1024* ONE_MEGABYTE) +#define ONE_TERRABYTE ((curl_off_t)1024* ONE_GIGABYTE) +#define ONE_PETABYTE ((curl_off_t)1024* ONE_TERRABYTE) if(bytes < 100000) { sprintf(max5, "%5" FORMAT_OFF_T, bytes); @@ -84,14 +86,31 @@ static char *max5data(curl_off_t bytes, char *max5) (int)(bytes%ONE_MEGABYTE)/(ONE_MEGABYTE/10) ); } #if SIZEOF_CURL_OFF_T > 4 - else if(bytes < ((curl_off_t)10000*ONE_MEGABYTE)) { + else if(bytes < ( (curl_off_t)10000*ONE_MEGABYTE)) + /* 'XXXXM' is good until we're at 10000MB or above */ sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); - } - else - /* 10000 MB - 8589934587 GB !! */ + + else if(bytes < (curl_off_t)100*ONE_GIGABYTE) + /* 10000 MB - 100 GB, we show it as XX.XG */ sprintf(max5, "%2d.%0dG", (int)(bytes/ONE_GIGABYTE), (int)(bytes%ONE_GIGABYTE)/(ONE_GIGABYTE/10) ); + + else if(bytes < (curl_off_t)10000 * ONE_GIGABYTE) + /* up to 10000GB, display without decimal: XXXXG */ + sprintf(max5, "%4dG", (int)(bytes/ONE_GIGABYTE)); + + else if(bytes < (curl_off_t)10000 * ONE_TERRABYTE) + /* up to 10000TB, display without decimal: XXXXT */ + sprintf(max5, "%4dT", (int)(bytes/ONE_TERRABYTE)); + else { + /* up to 10000PB, display without decimal: XXXXP */ + sprintf(max5, "%4dP", (int)(bytes/ONE_PETABYTE)); + + /* 16384 petabytes (16 exabytes) is maximum a 64 bit number can hold, + but this type is signed so 8192PB will be max.*/ + } + #else else sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); -- cgit v1.2.3