1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

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...
This commit is contained in:
Daniel Stenberg 2004-05-05 08:43:23 +00:00
parent caf7854a3c
commit 6062ac7c37

View File

@ -68,8 +68,10 @@ static void time2str(char *r, long t)
static char *max5data(curl_off_t bytes, char *max5) static char *max5data(curl_off_t bytes, char *max5)
{ {
#define ONE_KILOBYTE 1024 #define ONE_KILOBYTE 1024
#define ONE_MEGABYTE (1024*1024) #define ONE_MEGABYTE (1024* ONE_KILOBYTE)
#define ONE_GIGABYTE (1024*1024*1024) #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) { if(bytes < 100000) {
sprintf(max5, "%5" FORMAT_OFF_T, bytes); 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) ); (int)(bytes%ONE_MEGABYTE)/(ONE_MEGABYTE/10) );
} }
#if SIZEOF_CURL_OFF_T > 4 #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)); sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE));
}
else else if(bytes < (curl_off_t)100*ONE_GIGABYTE)
/* 10000 MB - 8589934587 GB !! */ /* 10000 MB - 100 GB, we show it as XX.XG */
sprintf(max5, "%2d.%0dG", sprintf(max5, "%2d.%0dG",
(int)(bytes/ONE_GIGABYTE), (int)(bytes/ONE_GIGABYTE),
(int)(bytes%ONE_GIGABYTE)/(ONE_GIGABYTE/10) ); (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
else else
sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE));