diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-09 12:20:57 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-09 12:20:57 +0000 |
commit | 3526a1320a7e70be0def06a31b65ffff3430510b (patch) | |
tree | 31bf441da4814976ecfc9d8acf70eb3fd496e62b | |
parent | d797fcd72644f772090c79464d293f37607b9698 (diff) | |
download | busybox-w32-3526a1320a7e70be0def06a31b65ffff3430510b.tar.gz busybox-w32-3526a1320a7e70be0def06a31b65ffff3430510b.tar.bz2 busybox-w32-3526a1320a7e70be0def06a31b65ffff3430510b.zip |
wget: wrap one atrociously long line (around 200 chars long!).
-rw-r--r-- | networking/wget.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/networking/wget.c b/networking/wget.c index c3b9fc039..f0ef3e485 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -41,7 +41,7 @@ static inline void progressmeter(int flag) {} | |||
41 | 41 | ||
42 | static void close_and_delete_outfile(FILE* output, char *fname_out, int do_continue) | 42 | static void close_and_delete_outfile(FILE* output, char *fname_out, int do_continue) |
43 | { | 43 | { |
44 | if (output != stdout && do_continue==0) { | 44 | if (output != stdout && do_continue == 0) { |
45 | fclose(output); | 45 | fclose(output); |
46 | unlink(fname_out); | 46 | unlink(fname_out); |
47 | } | 47 | } |
@@ -100,8 +100,8 @@ static char *safe_fgets(char *s, int size, FILE *stream) | |||
100 | /* | 100 | /* |
101 | * Base64-encode character string and return the string. | 101 | * Base64-encode character string and return the string. |
102 | */ | 102 | */ |
103 | static char *base64enc(unsigned char *p, char *buf, int len) { | 103 | static char *base64enc(unsigned char *p, char *buf, int len) |
104 | 104 | { | |
105 | bb_uuencode(p, buf, len, bb_uuenc_tbl_base64); | 105 | bb_uuencode(p, buf, len, bb_uuenc_tbl_base64); |
106 | return buf; | 106 | return buf; |
107 | } | 107 | } |
@@ -182,7 +182,8 @@ int wget_main(int argc, char **argv) | |||
182 | while (headers_llist) { | 182 | while (headers_llist) { |
183 | int arglen = strlen(headers_llist->data); | 183 | int arglen = strlen(headers_llist->data); |
184 | if (extra_headers_left - arglen - 2 <= 0) | 184 | if (extra_headers_left - arglen - 2 <= 0) |
185 | bb_error_msg_and_die("extra_headers buffer too small(need %i)", extra_headers_left - arglen); | 185 | bb_error_msg_and_die("extra_headers buffer too small " |
186 | "(need %i)", extra_headers_left - arglen); | ||
186 | strcpy(extra_headers_ptr, headers_llist->data); | 187 | strcpy(extra_headers_ptr, headers_llist->data); |
187 | extra_headers_ptr += arglen; | 188 | extra_headers_ptr += arglen; |
188 | extra_headers_left -= ( arglen + 2 ); | 189 | extra_headers_left -= ( arglen + 2 ); |
@@ -213,14 +214,14 @@ int wget_main(int argc, char **argv) | |||
213 | if (!fname_out) { | 214 | if (!fname_out) { |
214 | // Dirty hack. Needed because bb_get_last_path_component | 215 | // Dirty hack. Needed because bb_get_last_path_component |
215 | // will destroy trailing / by storing '\0' in last byte! | 216 | // will destroy trailing / by storing '\0' in last byte! |
216 | if(*target.path && target.path[strlen(target.path)-1]!='/') { | 217 | if (*target.path && target.path[strlen(target.path)-1] != '/') { |
217 | fname_out = | 218 | fname_out = |
218 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 219 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR |
219 | curfile = | 220 | curfile = |
220 | #endif | 221 | #endif |
221 | bb_get_last_path_component(target.path); | 222 | bb_get_last_path_component(target.path); |
222 | } | 223 | } |
223 | if (fname_out==NULL || strlen(fname_out)<1) { | 224 | if (fname_out == NULL || strlen(fname_out) < 1) { |
224 | fname_out = | 225 | fname_out = |
225 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 226 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR |
226 | curfile = | 227 | curfile = |
@@ -253,7 +254,7 @@ int wget_main(int argc, char **argv) | |||
253 | */ | 254 | */ |
254 | if (do_continue) { | 255 | if (do_continue) { |
255 | if (fstat(fileno(output), &sbuf) < 0) | 256 | if (fstat(fileno(output), &sbuf) < 0) |
256 | bb_perror_msg_and_die("fstat()"); | 257 | bb_perror_msg_and_die("fstat"); |
257 | if (sbuf.st_size > 0) | 258 | if (sbuf.st_size > 0) |
258 | beg_range = sbuf.st_size; | 259 | beg_range = sbuf.st_size; |
259 | else | 260 | else |
@@ -265,8 +266,8 @@ int wget_main(int argc, char **argv) | |||
265 | * and we want to connect to only one IP... */ | 266 | * and we want to connect to only one IP... */ |
266 | bb_lookup_host(&s_in, server.host); | 267 | bb_lookup_host(&s_in, server.host); |
267 | s_in.sin_port = server.port; | 268 | s_in.sin_port = server.port; |
268 | if (quiet_flag==FALSE) { | 269 | if (quiet_flag == FALSE) { |
269 | fprintf(stdout, "Connecting to %s[%s]:%d\n", | 270 | printf("Connecting to %s[%s]:%d\n", |
270 | server.host, inet_ntoa(s_in.sin_addr), ntohs(server.port)); | 271 | server.host, inet_ntoa(s_in.sin_addr), ntohs(server.port)); |
271 | } | 272 | } |
272 | 273 | ||
@@ -277,7 +278,7 @@ int wget_main(int argc, char **argv) | |||
277 | do { | 278 | do { |
278 | got_clen = chunked = 0; | 279 | got_clen = chunked = 0; |
279 | 280 | ||
280 | if (! --try) | 281 | if (!--try) |
281 | close_delete_and_die("too many redirections"); | 282 | close_delete_and_die("too many redirections"); |
282 | 283 | ||
283 | /* | 284 | /* |
@@ -401,7 +402,7 @@ read_response: | |||
401 | /* | 402 | /* |
402 | * FTP session | 403 | * FTP session |
403 | */ | 404 | */ |
404 | if (! target.user) | 405 | if (!target.user) |
405 | target.user = xstrdup("anonymous:busybox@"); | 406 | target.user = xstrdup("anonymous:busybox@"); |
406 | 407 | ||
407 | sfp = open_socket(&s_in); | 408 | sfp = open_socket(&s_in); |
@@ -476,11 +477,17 @@ read_response: | |||
476 | filesize = strtol(buf, (char **) NULL, 16); | 477 | filesize = strtol(buf, (char **) NULL, 16); |
477 | } | 478 | } |
478 | 479 | ||
479 | if (quiet_flag==FALSE) | 480 | if (quiet_flag == FALSE) |
480 | progressmeter(-1); | 481 | progressmeter(-1); |
481 | 482 | ||
482 | do { | 483 | do { |
483 | while ((filesize > 0 || !got_clen) && (n = safe_fread(buf, 1, ((chunked || got_clen) && (filesize < sizeof(buf)) ? filesize : sizeof(buf)), dfp)) > 0) { | 484 | while (filesize > 0 || !got_clen) { |
485 | unsigned rdsz = sizeof(buf); | ||
486 | if (filesize < sizeof(buf) && (chunked || got_clen)) | ||
487 | rdsz = filesize; | ||
488 | n = safe_fread(buf, 1, rdsz, dfp); | ||
489 | if (n <= 0) | ||
490 | break; | ||
484 | if (safe_fwrite(buf, 1, n, output) != n) { | 491 | if (safe_fwrite(buf, 1, n, output) != n) { |
485 | bb_perror_msg_and_die(bb_msg_write_error); | 492 | bb_perror_msg_and_die(bb_msg_write_error); |
486 | } | 493 | } |
@@ -496,7 +503,7 @@ read_response: | |||
496 | safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */ | 503 | safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */ |
497 | safe_fgets(buf, sizeof(buf), dfp); | 504 | safe_fgets(buf, sizeof(buf), dfp); |
498 | filesize = strtol(buf, (char **) NULL, 16); | 505 | filesize = strtol(buf, (char **) NULL, 16); |
499 | if (filesize==0) { | 506 | if (filesize == 0) { |
500 | chunked = 0; /* all done! */ | 507 | chunked = 0; /* all done! */ |
501 | } | 508 | } |
502 | } | 509 | } |
@@ -506,7 +513,7 @@ read_response: | |||
506 | } | 513 | } |
507 | } while (chunked); | 514 | } while (chunked); |
508 | 515 | ||
509 | if (quiet_flag==FALSE) | 516 | if (quiet_flag == FALSE) |
510 | progressmeter(1); | 517 | progressmeter(1); |
511 | 518 | ||
512 | if ((use_proxy == 0) && target.is_ftp) { | 519 | if ((use_proxy == 0) && target.is_ftp) { |
@@ -580,7 +587,7 @@ FILE *open_socket(struct sockaddr_in *s_in) | |||
580 | 587 | ||
581 | fp = fdopen(xconnect(s_in), "r+"); | 588 | fp = fdopen(xconnect(s_in), "r+"); |
582 | if (fp == NULL) | 589 | if (fp == NULL) |
583 | bb_perror_msg_and_die("fdopen()"); | 590 | bb_perror_msg_and_die("fdopen"); |
584 | 591 | ||
585 | return fp; | 592 | return fp; |
586 | } | 593 | } |
@@ -645,13 +652,13 @@ static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf) | |||
645 | char *buf_ptr; | 652 | char *buf_ptr; |
646 | 653 | ||
647 | if (fgets(buf, 510, fp) == NULL) { | 654 | if (fgets(buf, 510, fp) == NULL) { |
648 | bb_perror_msg_and_die("fgets()"); | 655 | bb_perror_msg_and_die("fgets"); |
649 | } | 656 | } |
650 | buf_ptr = strstr(buf, "\r\n"); | 657 | buf_ptr = strstr(buf, "\r\n"); |
651 | if (buf_ptr) { | 658 | if (buf_ptr) { |
652 | *buf_ptr = '\0'; | 659 | *buf_ptr = '\0'; |
653 | } | 660 | } |
654 | } while (! isdigit(buf[0]) || buf[3] != ' '); | 661 | } while (!isdigit(buf[0]) || buf[3] != ' '); |
655 | 662 | ||
656 | return atoi(buf); | 663 | return atoi(buf); |
657 | } | 664 | } |