aboutsummaryrefslogtreecommitdiff
path: root/lib/progress.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-05-05 08:43:23 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-05-05 08:43:23 +0000
commit6062ac7c37c9290f1c4951d6b7bfc02ac3cadefe (patch)
tree1d6633a583424b4ea6ab452eb70ea674584960ad /lib/progress.c
parentcaf7854a3ce16933557ad6ff33e6b210a2109b48 (diff)
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...
Diffstat (limited to 'lib/progress.c')
-rw-r--r--lib/progress.c31
1 files changed, 25 insertions, 6 deletions
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));