aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-03-11 21:48:15 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-03-11 21:48:15 +0000
commit1d5a914c1c0a82e0a633f559d6500027e3030253 (patch)
tree2b1b322c5828e35f848e7f8a8167bb39168ab490 /lib
parent666bc9ee4ed33b00f02f275722706638a614077b (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')
-rw-r--r--lib/progress.c34
-rw-r--r--lib/urldata.h6
2 files changed, 21 insertions, 19 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 =
diff --git a/lib/urldata.h b/lib/urldata.h
index d57d0a5fa..4e7b14e3f 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -609,7 +609,7 @@ struct Progress {
curl_off_t downloaded; /* transfered so far */
curl_off_t uploaded; /* transfered so far */
- double current_speed; /* uses the currently fastest transfer */
+ curl_off_t current_speed; /* uses the currently fastest transfer */
bool callback; /* set when progress callback is used */
int width; /* screen width at download start */
@@ -617,8 +617,8 @@ struct Progress {
double timespent;
- double dlspeed;
- double ulspeed;
+ curl_off_t dlspeed;
+ curl_off_t ulspeed;
double t_nslookup;
double t_connect;