diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-11 12:36:10 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-11 12:36:10 +0100 |
| commit | a3aa3e309506ea96fa8f7546f6b22fa85263a934 (patch) | |
| tree | cd6d4adeafec55e230e2d56499df8f0c3cbf47e1 | |
| parent | 4662de0511487b4da965c4b2158bae318f3d80a8 (diff) | |
| download | busybox-w32-a3aa3e309506ea96fa8f7546f6b22fa85263a934.tar.gz busybox-w32-a3aa3e309506ea96fa8f7546f6b22fa85263a934.tar.bz2 busybox-w32-a3aa3e309506ea96fa8f7546f6b22fa85263a934.zip | |
wget: check for close success; fix chunked; do not bother to send QUIT to ftp
Also, random fixes to use %u for unsigned quantities. -14 bytes in wget.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | archival/tar.c | 2 | ||||
| -rw-r--r-- | editors/cmp.c | 6 | ||||
| -rw-r--r-- | networking/ftpgetput.c | 2 | ||||
| -rw-r--r-- | networking/httpd.c | 4 | ||||
| -rw-r--r-- | networking/wget.c | 62 | ||||
| -rw-r--r-- | util-linux/more.c | 2 |
6 files changed, 41 insertions, 37 deletions
diff --git a/archival/tar.c b/archival/tar.c index c12331c83..d6c44a7b7 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
| @@ -336,7 +336,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo, | |||
| 336 | && statbuf->st_size > (off_t)0777777777777LL | 336 | && statbuf->st_size > (off_t)0777777777777LL |
| 337 | ) { | 337 | ) { |
| 338 | bb_error_msg_and_die("can't store file '%s' " | 338 | bb_error_msg_and_die("can't store file '%s' " |
| 339 | "of size %"OFF_FMT"d, aborting", | 339 | "of size %"OFF_FMT"u, aborting", |
| 340 | fileName, statbuf->st_size); | 340 | fileName, statbuf->st_size); |
| 341 | } | 341 | } |
| 342 | header.typeflag = REGTYPE; | 342 | header.typeflag = REGTYPE; |
diff --git a/editors/cmp.c b/editors/cmp.c index 384e57c22..0cb80f21e 100644 --- a/editors/cmp.c +++ b/editors/cmp.c | |||
| @@ -24,9 +24,9 @@ | |||
| 24 | #include "libbb.h" | 24 | #include "libbb.h" |
| 25 | 25 | ||
| 26 | static const char fmt_eof[] ALIGN1 = "cmp: EOF on %s\n"; | 26 | static const char fmt_eof[] ALIGN1 = "cmp: EOF on %s\n"; |
| 27 | static const char fmt_differ[] ALIGN1 = "%s %s differ: char %"OFF_FMT"d, line %d\n"; | 27 | static const char fmt_differ[] ALIGN1 = "%s %s differ: char %"OFF_FMT"u, line %u\n"; |
| 28 | // This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"d %o %o\n" | 28 | // This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"u %o %o\n" |
| 29 | static const char fmt_l_opt[] ALIGN1 = "%.0s%.0s%"OFF_FMT"d %3o %3o\n"; | 29 | static const char fmt_l_opt[] ALIGN1 = "%.0s%.0s%"OFF_FMT"u %3o %3o\n"; |
| 30 | 30 | ||
| 31 | static const char opt_chars[] ALIGN1 = "sl"; | 31 | static const char opt_chars[] ALIGN1 = "sl"; |
| 32 | #define CMP_OPT_s (1<<0) | 32 | #define CMP_OPT_s (1<<0) |
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index c0ecddac1..2dd7e9232 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c | |||
| @@ -212,7 +212,7 @@ int ftp_receive(const char *local_path, char *server_path) | |||
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | if (do_continue) { | 214 | if (do_continue) { |
| 215 | sprintf(buf, "REST %"OFF_FMT"d", beg_range); | 215 | sprintf(buf, "REST %"OFF_FMT"u", beg_range); |
| 216 | if (ftpcmd(buf, NULL) != 350) { | 216 | if (ftpcmd(buf, NULL) != 350) { |
| 217 | do_continue = 0; | 217 | do_continue = 0; |
| 218 | } | 218 | } |
diff --git a/networking/httpd.c b/networking/httpd.c index a2a52b58a..7ac43619a 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
| @@ -1021,7 +1021,7 @@ static void send_headers(int responseNum) | |||
| 1021 | strftime(tmp_str, sizeof(tmp_str), RFC1123FMT, gmtime(&last_mod)); | 1021 | strftime(tmp_str, sizeof(tmp_str), RFC1123FMT, gmtime(&last_mod)); |
| 1022 | #if ENABLE_FEATURE_HTTPD_RANGES | 1022 | #if ENABLE_FEATURE_HTTPD_RANGES |
| 1023 | if (responseNum == HTTP_PARTIAL_CONTENT) { | 1023 | if (responseNum == HTTP_PARTIAL_CONTENT) { |
| 1024 | len += sprintf(iobuf + len, "Content-Range: bytes %"OFF_FMT"d-%"OFF_FMT"d/%"OFF_FMT"d\r\n", | 1024 | len += sprintf(iobuf + len, "Content-Range: bytes %"OFF_FMT"u-%"OFF_FMT"u/%"OFF_FMT"u\r\n", |
| 1025 | range_start, | 1025 | range_start, |
| 1026 | range_end, | 1026 | range_end, |
| 1027 | file_size); | 1027 | file_size); |
| @@ -1032,7 +1032,7 @@ static void send_headers(int responseNum) | |||
| 1032 | #if ENABLE_FEATURE_HTTPD_RANGES | 1032 | #if ENABLE_FEATURE_HTTPD_RANGES |
| 1033 | "Accept-Ranges: bytes\r\n" | 1033 | "Accept-Ranges: bytes\r\n" |
| 1034 | #endif | 1034 | #endif |
| 1035 | "Last-Modified: %s\r\n%s %"OFF_FMT"d\r\n", | 1035 | "Last-Modified: %s\r\n%s %"OFF_FMT"u\r\n", |
| 1036 | tmp_str, | 1036 | tmp_str, |
| 1037 | "Content-length:", | 1037 | "Content-length:", |
| 1038 | file_size | 1038 | file_size |
diff --git a/networking/wget.c b/networking/wget.c index 8ca6def67..64553d49a 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
| @@ -35,10 +35,6 @@ struct globals { | |||
| 35 | struct BUG_G_too_big { | 35 | struct BUG_G_too_big { |
| 36 | char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1]; | 36 | char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1]; |
| 37 | }; | 37 | }; |
| 38 | #define content_len (G.content_len ) | ||
| 39 | #define beg_range (G.beg_range ) | ||
| 40 | #define transferred (G.transferred ) | ||
| 41 | #define curfile (G.curfile ) | ||
| 42 | #define INIT_G() do { } while (0) | 38 | #define INIT_G() do { } while (0) |
| 43 | 39 | ||
| 44 | 40 | ||
| @@ -53,14 +49,14 @@ static void progress_meter(int flag) | |||
| 53 | bb_progress_init(&G.pmt); | 49 | bb_progress_init(&G.pmt); |
| 54 | } | 50 | } |
| 55 | 51 | ||
| 56 | bb_progress_update(&G.pmt, curfile, beg_range, transferred, | 52 | bb_progress_update(&G.pmt, G.curfile, G.beg_range, G.transferred, |
| 57 | G.chunked ? 0 : content_len + beg_range); | 53 | G.chunked ? 0 : G.content_len + G.beg_range); |
| 58 | 54 | ||
| 59 | if (flag == 0) { | 55 | if (flag == 0) { |
| 60 | /* last call to progress_meter */ | 56 | /* last call to progress_meter */ |
| 61 | alarm(0); | 57 | alarm(0); |
| 62 | fputc('\n', stderr); | 58 | fputc('\n', stderr); |
| 63 | transferred = 0; | 59 | G.transferred = 0; |
| 64 | } else { | 60 | } else { |
| 65 | if (flag == -1) { /* first call to progress_meter */ | 61 | if (flag == -1) { /* first call to progress_meter */ |
| 66 | signal_SA_RESTART_empty_mask(SIGALRM, progress_meter); | 62 | signal_SA_RESTART_empty_mask(SIGALRM, progress_meter); |
| @@ -390,8 +386,8 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_ | |||
| 390 | * Querying file size | 386 | * Querying file size |
| 391 | */ | 387 | */ |
| 392 | if (ftpcmd("SIZE ", target->path, sfp, buf) == 213) { | 388 | if (ftpcmd("SIZE ", target->path, sfp, buf) == 213) { |
| 393 | content_len = BB_STRTOOFF(buf+4, NULL, 10); | 389 | G.content_len = BB_STRTOOFF(buf+4, NULL, 10); |
| 394 | if (errno || content_len < 0) { | 390 | if (G.content_len < 0 || errno) { |
| 395 | bb_error_msg_and_die("SIZE value is garbage"); | 391 | bb_error_msg_and_die("SIZE value is garbage"); |
| 396 | } | 392 | } |
| 397 | G.got_clen = 1; | 393 | G.got_clen = 1; |
| @@ -420,10 +416,10 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_ | |||
| 420 | 416 | ||
| 421 | *dfpp = open_socket(lsa); | 417 | *dfpp = open_socket(lsa); |
| 422 | 418 | ||
| 423 | if (beg_range) { | 419 | if (G.beg_range) { |
| 424 | sprintf(buf, "REST %"OFF_FMT"d", beg_range); | 420 | sprintf(buf, "REST %"OFF_FMT"u", G.beg_range); |
| 425 | if (ftpcmd(buf, NULL, sfp, buf) == 350) | 421 | if (ftpcmd(buf, NULL, sfp, buf) == 350) |
| 426 | content_len -= beg_range; | 422 | G.content_len -= G.beg_range; |
| 427 | } | 423 | } |
| 428 | 424 | ||
| 429 | if (ftpcmd("RETR ", target->path, sfp, buf) > 150) | 425 | if (ftpcmd("RETR ", target->path, sfp, buf) > 150) |
| @@ -460,12 +456,18 @@ static void NOINLINE retrieve_file_data(FILE *dfp, int output_fd) | |||
| 460 | 456 | ||
| 461 | /* Loops only if chunked */ | 457 | /* Loops only if chunked */ |
| 462 | while (1) { | 458 | while (1) { |
| 463 | while (content_len > 0 || !G.got_clen) { | 459 | while (1) { |
| 464 | int n; | 460 | int n; |
| 465 | unsigned rdsz = sizeof(buf); | 461 | unsigned rdsz; |
| 466 | 462 | ||
| 467 | if (content_len < sizeof(buf) && (G.chunked || G.got_clen)) | 463 | rdsz = sizeof(buf); |
| 468 | rdsz = (unsigned)content_len; | 464 | if (G.got_clen) { |
| 465 | if (G.content_len < sizeof(buf)) { | ||
| 466 | if ((int)G.content_len <= 0) | ||
| 467 | break; | ||
| 468 | rdsz = (unsigned)G.content_len; | ||
| 469 | } | ||
| 470 | } | ||
| 469 | n = safe_fread(buf, rdsz, dfp); | 471 | n = safe_fread(buf, rdsz, dfp); |
| 470 | if (n <= 0) { | 472 | if (n <= 0) { |
| 471 | if (ferror(dfp)) { | 473 | if (ferror(dfp)) { |
| @@ -476,10 +478,10 @@ static void NOINLINE retrieve_file_data(FILE *dfp, int output_fd) | |||
| 476 | } | 478 | } |
| 477 | xwrite(output_fd, buf, n); | 479 | xwrite(output_fd, buf, n); |
| 478 | #if ENABLE_FEATURE_WGET_STATUSBAR | 480 | #if ENABLE_FEATURE_WGET_STATUSBAR |
| 479 | transferred += n; | 481 | G.transferred += n; |
| 480 | #endif | 482 | #endif |
| 481 | if (G.got_clen) | 483 | if (G.got_clen) |
| 482 | content_len -= n; | 484 | G.content_len -= n; |
| 483 | } | 485 | } |
| 484 | 486 | ||
| 485 | if (!G.chunked) | 487 | if (!G.chunked) |
| @@ -488,10 +490,11 @@ static void NOINLINE retrieve_file_data(FILE *dfp, int output_fd) | |||
| 488 | safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */ | 490 | safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */ |
| 489 | get_clen: | 491 | get_clen: |
| 490 | safe_fgets(buf, sizeof(buf), dfp); | 492 | safe_fgets(buf, sizeof(buf), dfp); |
| 491 | content_len = STRTOOFF(buf, NULL, 16); | 493 | G.content_len = STRTOOFF(buf, NULL, 16); |
| 492 | /* FIXME: error check? */ | 494 | /* FIXME: error check? */ |
| 493 | if (content_len == 0) | 495 | if (G.content_len == 0) |
| 494 | break; /* all done! */ | 496 | break; /* all done! */ |
| 497 | G.got_clen = 1; | ||
| 495 | } | 498 | } |
| 496 | 499 | ||
| 497 | if (!(option_mask32 & WGET_OPT_QUIET)) | 500 | if (!(option_mask32 & WGET_OPT_QUIET)) |
| @@ -621,7 +624,7 @@ int wget_main(int argc UNUSED_PARAM, char **argv) | |||
| 621 | } | 624 | } |
| 622 | } | 625 | } |
| 623 | #if ENABLE_FEATURE_WGET_STATUSBAR | 626 | #if ENABLE_FEATURE_WGET_STATUSBAR |
| 624 | curfile = bb_get_last_path_component_nostrip(fname_out); | 627 | G.curfile = bb_get_last_path_component_nostrip(fname_out); |
| 625 | #endif | 628 | #endif |
| 626 | 629 | ||
| 627 | /* Impossible? | 630 | /* Impossible? |
| @@ -633,7 +636,7 @@ int wget_main(int argc UNUSED_PARAM, char **argv) | |||
| 633 | if (opt & WGET_OPT_CONTINUE) { | 636 | if (opt & WGET_OPT_CONTINUE) { |
| 634 | output_fd = open(fname_out, O_WRONLY); | 637 | output_fd = open(fname_out, O_WRONLY); |
| 635 | if (output_fd >= 0) { | 638 | if (output_fd >= 0) { |
| 636 | beg_range = xlseek(output_fd, 0, SEEK_END); | 639 | G.beg_range = xlseek(output_fd, 0, SEEK_END); |
| 637 | } | 640 | } |
| 638 | /* File doesn't exist. We do not create file here yet. | 641 | /* File doesn't exist. We do not create file here yet. |
| 639 | * We are not sure it exists on remove side */ | 642 | * We are not sure it exists on remove side */ |
| @@ -684,8 +687,8 @@ int wget_main(int argc UNUSED_PARAM, char **argv) | |||
| 684 | } | 687 | } |
| 685 | #endif | 688 | #endif |
| 686 | 689 | ||
| 687 | if (beg_range) | 690 | if (G.beg_range) |
| 688 | fprintf(sfp, "Range: bytes=%"OFF_FMT"d-\r\n", beg_range); | 691 | fprintf(sfp, "Range: bytes=%"OFF_FMT"u-\r\n", G.beg_range); |
| 689 | #if ENABLE_FEATURE_WGET_LONG_OPTIONS | 692 | #if ENABLE_FEATURE_WGET_LONG_OPTIONS |
| 690 | if (extra_headers) | 693 | if (extra_headers) |
| 691 | fputs(extra_headers, sfp); | 694 | fputs(extra_headers, sfp); |
| @@ -756,7 +759,7 @@ However, in real world it was observed that some web servers | |||
| 756 | case 303: | 759 | case 303: |
| 757 | break; | 760 | break; |
| 758 | case 206: | 761 | case 206: |
| 759 | if (beg_range) | 762 | if (G.beg_range) |
| 760 | break; | 763 | break; |
| 761 | /* fall through */ | 764 | /* fall through */ |
| 762 | default: | 765 | default: |
| @@ -777,8 +780,8 @@ However, in real world it was observed that some web servers | |||
| 777 | } | 780 | } |
| 778 | key = index_in_strings(keywords, buf) + 1; | 781 | key = index_in_strings(keywords, buf) + 1; |
| 779 | if (key == KEY_content_length) { | 782 | if (key == KEY_content_length) { |
| 780 | content_len = BB_STRTOOFF(str, NULL, 10); | 783 | G.content_len = BB_STRTOOFF(str, NULL, 10); |
| 781 | if (errno || content_len < 0) { | 784 | if (G.content_len < 0 || errno) { |
| 782 | bb_error_msg_and_die("content-length %s is garbage", sanitize_string(str)); | 785 | bb_error_msg_and_die("content-length %s is garbage", sanitize_string(str)); |
| 783 | } | 786 | } |
| 784 | G.got_clen = 1; | 787 | G.got_clen = 1; |
| @@ -841,13 +844,14 @@ However, in real world it was observed that some web servers | |||
| 841 | } | 844 | } |
| 842 | 845 | ||
| 843 | retrieve_file_data(dfp, output_fd); | 846 | retrieve_file_data(dfp, output_fd); |
| 847 | xclose(output_fd); | ||
| 844 | 848 | ||
| 845 | if (dfp != sfp) { | 849 | if (dfp != sfp) { |
| 846 | /* It's ftp. Close it properly */ | 850 | /* It's ftp. Close it properly */ |
| 847 | fclose(dfp); | 851 | fclose(dfp); |
| 848 | if (ftpcmd(NULL, NULL, sfp, buf) != 226) | 852 | if (ftpcmd(NULL, NULL, sfp, buf) != 226) |
| 849 | bb_error_msg_and_die("ftp error: %s", sanitize_string(buf+4)); | 853 | bb_error_msg_and_die("ftp error: %s", sanitize_string(buf+4)); |
| 850 | ftpcmd("QUIT", NULL, sfp, buf); | 854 | /* ftpcmd("QUIT", NULL, sfp, buf); - why bother? */ |
| 851 | } | 855 | } |
| 852 | 856 | ||
| 853 | return EXIT_SUCCESS; | 857 | return EXIT_SUCCESS; |
diff --git a/util-linux/more.c b/util-linux/more.c index 555f033d4..076b40057 100644 --- a/util-linux/more.c +++ b/util-linux/more.c | |||
| @@ -110,7 +110,7 @@ int more_main(int argc UNUSED_PARAM, char **argv) | |||
| 110 | if (input != 'r' && please_display_more_prompt) { | 110 | if (input != 'r' && please_display_more_prompt) { |
| 111 | len = printf("--More-- "); | 111 | len = printf("--More-- "); |
| 112 | if (st.st_size > 0) { | 112 | if (st.st_size > 0) { |
| 113 | len += printf("(%d%% of %"OFF_FMT"d bytes)", | 113 | len += printf("(%u%% of %"OFF_FMT"u bytes)", |
| 114 | (int) (ftello(file)*100 / st.st_size), | 114 | (int) (ftello(file)*100 / st.st_size), |
| 115 | st.st_size); | 115 | st.st_size); |
| 116 | } | 116 | } |
