diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-03-11 21:48:15 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-03-11 21:48:15 +0000 |
commit | 1d5a914c1c0a82e0a633f559d6500027e3030253 (patch) | |
tree | 2b1b322c5828e35f848e7f8a8167bb39168ab490 /lib/progress.c | |
parent | 666bc9ee4ed33b00f02f275722706638a614077b (diff) |
Made max5data() take a curl_off_t size as argument instead of double. Should
make the progress meter more accurate for large files. Also made the sprintf
usage in that function avoid floating point.
Diffstat (limited to 'lib/progress.c')
-rw-r--r-- | lib/progress.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/progress.c b/lib/progress.c index d0421ca6c..23ac0defe 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -53,34 +53,36 @@ static void time2str(char *r, int t) /* The point of this function would be to return a string of the input data, but never longer than 5 columns. Add suffix k, M, G when suitable... */ -static char *max5data(double bytes, char *max5) +static char *max5data(curl_off_t bytes, char *max5) { #define ONE_KILOBYTE 1024 #define ONE_MEGABYTE (1024*1024) #define ONE_GIGABYTE (1024*1024*1024) if(bytes < 100000) { - sprintf(max5, "%5" FORMAT_OFF_T, (curl_off_t)bytes); - return max5; + sprintf(max5, "%5" FORMAT_OFF_T, bytes); } - if(bytes < (10000*ONE_KILOBYTE)) { - sprintf(max5, "%4" FORMAT_OFF_T "k", (curl_off_t)bytes/ONE_KILOBYTE); - return max5; + else if(bytes < (10000*ONE_KILOBYTE)) { + sprintf(max5, "%4" FORMAT_OFF_T "k", (curl_off_t)(bytes/ONE_KILOBYTE)); } - if(bytes < (100*ONE_MEGABYTE)) { + else if(bytes < (100*ONE_MEGABYTE)) { /* 'XX.XM' is good as long as we're less than 100 megs */ - sprintf(max5, "%4.1fM", bytes/ONE_MEGABYTE); - return max5; + sprintf(max5, "%2d.%0dM", + (int)(bytes/ONE_MEGABYTE), + (int)(bytes%ONE_MEGABYTE)/(ONE_MEGABYTE/10) ); } #if SIZEOF_CURL_OFF_T > 4 - if((curl_off_t)bytes < ((curl_off_t)10000*ONE_MEGABYTE)) { - sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)bytes/ONE_MEGABYTE); - return max5; + else if(bytes < ((curl_off_t)10000*ONE_MEGABYTE)) { + sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); } - /* 10000 MB - 8589934587 GB !! */ - sprintf(max5, "%4.1fG", bytes/ONE_GIGABYTE); + else + /* 10000 MB - 8589934587 GB !! */ + sprintf(max5, "%2d.%0dG", + (int)(bytes/ONE_GIGABYTE), + (int)(bytes%ONE_GIGABYTE)/(ONE_GIGABYTE/10) ); #else - sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)bytes/ONE_MEGABYTE); + else + sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); #endif return max5; @@ -259,7 +261,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* The average download speed this far */ data->progress.dlspeed = - data->progress.downloaded/(timespent>0.01?timespent:1.0); + data->progress.downloaded/(timespent>0.01?timespent:1); /* The average upload speed this far */ data->progress.ulspeed = |