diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-21 10:43:02 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-21 10:43:02 +0000 |
commit | 9cade08917028a453d9376dc44482ba2801921ca (patch) | |
tree | 3afd967130126931aa2dddbbd939e871272df7a8 /networking/wget.c | |
parent | 04291bc5aee1e020997894cfd497d14392ad2ced (diff) | |
download | busybox-w32-9cade08917028a453d9376dc44482ba2801921ca.tar.gz busybox-w32-9cade08917028a453d9376dc44482ba2801921ca.tar.bz2 busybox-w32-9cade08917028a453d9376dc44482ba2801921ca.zip |
wget: reduce likelihood of ETA overflow (especially with !LFS)
Diffstat (limited to 'networking/wget.c')
-rw-r--r-- | networking/wget.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/networking/wget.c b/networking/wget.c index a4c6289cb..69cabfc7f 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -31,11 +31,11 @@ static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf); | |||
31 | /* Globals (can be accessed from signal handlers */ | 31 | /* Globals (can be accessed from signal handlers */ |
32 | static off_t content_len; /* Content-length of the file */ | 32 | static off_t content_len; /* Content-length of the file */ |
33 | static off_t beg_range; /* Range at which continue begins */ | 33 | static off_t beg_range; /* Range at which continue begins */ |
34 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 34 | #if ENABLE_FEATURE_WGET_STATUSBAR |
35 | static off_t transferred; /* Number of bytes transferred so far */ | 35 | static off_t transferred; /* Number of bytes transferred so far */ |
36 | #endif | 36 | #endif |
37 | static int chunked; /* chunked transfer encoding */ | 37 | static int chunked; /* chunked transfer encoding */ |
38 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 38 | #if ENABLE_FEATURE_WGET_STATUSBAR |
39 | static void progressmeter(int flag); | 39 | static void progressmeter(int flag); |
40 | static char *curfile; /* Name of current file being transferred */ | 40 | static char *curfile; /* Name of current file being transferred */ |
41 | static struct timeval start; /* Time a transfer started */ | 41 | static struct timeval start; /* Time a transfer started */ |
@@ -75,7 +75,7 @@ static char *safe_fgets(char *s, int size, FILE *stream) | |||
75 | return ret; | 75 | return ret; |
76 | } | 76 | } |
77 | 77 | ||
78 | #ifdef CONFIG_FEATURE_WGET_AUTHENTICATION | 78 | #if ENABLE_FEATURE_WGET_AUTHENTICATION |
79 | /* | 79 | /* |
80 | * Base64-encode character string and return the string. | 80 | * Base64-encode character string and return the string. |
81 | */ | 81 | */ |
@@ -191,21 +191,21 @@ int wget_main(int argc, char **argv) | |||
191 | // will destroy trailing / by storing '\0' in last byte! | 191 | // will destroy trailing / by storing '\0' in last byte! |
192 | if (*target.path && target.path[strlen(target.path)-1] != '/') { | 192 | if (*target.path && target.path[strlen(target.path)-1] != '/') { |
193 | fname_out = | 193 | fname_out = |
194 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 194 | #if ENABLE_FEATURE_WGET_STATUSBAR |
195 | curfile = | 195 | curfile = |
196 | #endif | 196 | #endif |
197 | bb_get_last_path_component(target.path); | 197 | bb_get_last_path_component(target.path); |
198 | } | 198 | } |
199 | if (!fname_out || !fname_out[0]) { | 199 | if (!fname_out || !fname_out[0]) { |
200 | fname_out = | 200 | fname_out = |
201 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 201 | #if ENABLE_FEATURE_WGET_STATUSBAR |
202 | curfile = | 202 | curfile = |
203 | #endif | 203 | #endif |
204 | "index.html"; | 204 | "index.html"; |
205 | } | 205 | } |
206 | if (dir_prefix != NULL) | 206 | if (dir_prefix != NULL) |
207 | fname_out = concat_path_file(dir_prefix, fname_out); | 207 | fname_out = concat_path_file(dir_prefix, fname_out); |
208 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 208 | #if ENABLE_FEATURE_WGET_STATUSBAR |
209 | } else { | 209 | } else { |
210 | curfile = bb_get_last_path_component(fname_out); | 210 | curfile = bb_get_last_path_component(fname_out); |
211 | #endif | 211 | #endif |
@@ -260,7 +260,7 @@ int wget_main(int argc, char **argv) | |||
260 | */ | 260 | */ |
261 | if (use_proxy) { | 261 | if (use_proxy) { |
262 | const char *format = "GET %stp://%s:%d/%s HTTP/1.1\r\n"; | 262 | const char *format = "GET %stp://%s:%d/%s HTTP/1.1\r\n"; |
263 | #ifdef CONFIG_FEATURE_WGET_IP6_LITERAL | 263 | #if ENABLE_FEATURE_WGET_IP6_LITERAL |
264 | if (strchr(target.host, ':')) | 264 | if (strchr(target.host, ':')) |
265 | format = "GET %stp://[%s]:%d/%s HTTP/1.1\r\n"; | 265 | format = "GET %stp://[%s]:%d/%s HTTP/1.1\r\n"; |
266 | #endif | 266 | #endif |
@@ -274,7 +274,7 @@ int wget_main(int argc, char **argv) | |||
274 | fprintf(sfp, "Host: %s\r\nUser-Agent: %s\r\n", target.host, | 274 | fprintf(sfp, "Host: %s\r\nUser-Agent: %s\r\n", target.host, |
275 | user_agent); | 275 | user_agent); |
276 | 276 | ||
277 | #ifdef CONFIG_FEATURE_WGET_AUTHENTICATION | 277 | #if ENABLE_FEATURE_WGET_AUTHENTICATION |
278 | if (target.user) { | 278 | if (target.user) { |
279 | fprintf(sfp, "Authorization: Basic %s\r\n", | 279 | fprintf(sfp, "Authorization: Basic %s\r\n", |
280 | base64enc((unsigned char*)target.user, buf, sizeof(buf))); | 280 | base64enc((unsigned char*)target.user, buf, sizeof(buf))); |
@@ -466,7 +466,7 @@ int wget_main(int argc, char **argv) | |||
466 | if (full_write(output_fd, buf, n) != n) { | 466 | if (full_write(output_fd, buf, n) != n) { |
467 | bb_perror_msg_and_die(bb_msg_write_error); | 467 | bb_perror_msg_and_die(bb_msg_write_error); |
468 | } | 468 | } |
469 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 469 | #if ENABLE_FEATURE_WGET_STATUSBAR |
470 | transferred += n; | 470 | transferred += n; |
471 | #endif | 471 | #endif |
472 | if (got_clen) { | 472 | if (got_clen) { |
@@ -559,7 +559,7 @@ static void parse_url(char *src_url, struct host_info *h) | |||
559 | 559 | ||
560 | pp = h->host; | 560 | pp = h->host; |
561 | 561 | ||
562 | #ifdef CONFIG_FEATURE_WGET_IP6_LITERAL | 562 | #if ENABLE_FEATURE_WGET_IP6_LITERAL |
563 | if (h->host[0] == '[') { | 563 | if (h->host[0] == '[') { |
564 | char *ep; | 564 | char *ep; |
565 | 565 | ||
@@ -670,14 +670,14 @@ static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf) | |||
670 | return result; | 670 | return result; |
671 | } | 671 | } |
672 | 672 | ||
673 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 673 | #if ENABLE_FEATURE_WGET_STATUSBAR |
674 | /* Stuff below is from BSD rcp util.c, as added to openshh. | 674 | /* Stuff below is from BSD rcp util.c, as added to openshh. |
675 | * Original copyright notice is retained at the end of this file. | 675 | * Original copyright notice is retained at the end of this file. |
676 | */ | 676 | */ |
677 | static int | 677 | static int |
678 | getttywidth(void) | 678 | getttywidth(void) |
679 | { | 679 | { |
680 | int width=0; | 680 | int width; |
681 | get_terminal_width_height(0, &width, NULL); | 681 | get_terminal_width_height(0, &width, NULL); |
682 | return width; | 682 | return width; |
683 | } | 683 | } |
@@ -714,16 +714,17 @@ progressmeter(int flag) | |||
714 | char buf[256]; | 714 | char buf[256]; |
715 | 715 | ||
716 | if (flag == -1) { /* first call to progressmeter */ | 716 | if (flag == -1) { /* first call to progressmeter */ |
717 | (void) gettimeofday(&start, (struct timezone *) 0); | 717 | gettimeofday(&start, (struct timezone *) 0); |
718 | lastupdate = start; | 718 | lastupdate = start; |
719 | lastsize = 0; | 719 | lastsize = 0; |
720 | totalsize = content_len + beg_range; /* as content_len changes.. */ | 720 | totalsize = content_len + beg_range; /* as content_len changes.. */ |
721 | } | 721 | } |
722 | 722 | ||
723 | (void) gettimeofday(&now, (struct timezone *) 0); | 723 | gettimeofday(&now, (struct timezone *) 0); |
724 | ratio = 100; | 724 | ratio = 100; |
725 | if (totalsize != 0 && !chunked) { | 725 | if (totalsize != 0 && !chunked) { |
726 | ratio = (int) (100 * (transferred+beg_range) / totalsize); | 726 | /* long long helps to have working ETA even if !LFS */ |
727 | ratio = (int) (100 * (unsigned long long)(transferred+beg_range) / totalsize); | ||
727 | ratio = MIN(ratio, 100); | 728 | ratio = MIN(ratio, 100); |
728 | } | 729 | } |
729 | 730 | ||
@@ -743,7 +744,7 @@ progressmeter(int flag) | |||
743 | i++; | 744 | i++; |
744 | abbrevsize >>= 10; | 745 | abbrevsize >>= 10; |
745 | } | 746 | } |
746 | /* See http://en.wikipedia.org/wiki/Tera */ | 747 | /* see http://en.wikipedia.org/wiki/Tera */ |
747 | fprintf(stderr, "%6d %c%c ", (int)abbrevsize, " KMGTPEZY"[i], i?'B':' '); | 748 | fprintf(stderr, "%6d %c%c ", (int)abbrevsize, " KMGTPEZY"[i], i?'B':' '); |
748 | 749 | ||
749 | timersub(&now, &lastupdate, &tvwait); | 750 | timersub(&now, &lastupdate, &tvwait); |
@@ -765,7 +766,8 @@ progressmeter(int flag) | |||
765 | fprintf(stderr, "--:--:-- ETA"); | 766 | fprintf(stderr, "--:--:-- ETA"); |
766 | } else { | 767 | } else { |
767 | /* to_download / (transferred/elapsed) - elapsed: */ | 768 | /* to_download / (transferred/elapsed) - elapsed: */ |
768 | int eta = (int) (to_download*elapsed/transferred - elapsed); | 769 | int eta = (int) ((unsigned long long)to_download*elapsed/transferred - elapsed); |
770 | /* (long long helps to have working ETA even if !LFS) */ | ||
769 | i = eta % 3600; | 771 | i = eta % 3600; |
770 | fprintf(stderr, "%02d:%02d:%02d ETA", eta / 3600, i / 60, i % 60); | 772 | fprintf(stderr, "%02d:%02d:%02d ETA", eta / 3600, i / 60, i % 60); |
771 | } | 773 | } |