diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-02-13 02:49:43 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-02-13 02:49:43 +0100 |
commit | 9a5b7f636dad35ac84056768b3669bdca02d2700 (patch) | |
tree | 3d58d614fd30709c355b8455edc216eb5054c64a /networking/wget.c | |
parent | a3661096f2e8b49f66ce6c9bba71aa01b79098e2 (diff) | |
download | busybox-w32-9a5b7f636dad35ac84056768b3669bdca02d2700.tar.gz busybox-w32-9a5b7f636dad35ac84056768b3669bdca02d2700.tar.bz2 busybox-w32-9a5b7f636dad35ac84056768b3669bdca02d2700.zip |
wget: support multiple URLs on command line even without -O :)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/wget.c')
-rw-r--r-- | networking/wget.c | 70 |
1 files changed, 15 insertions, 55 deletions
diff --git a/networking/wget.c b/networking/wget.c index 76bd5e260..6c015dccc 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -140,41 +140,6 @@ static void strip_ipv6_scope_id(char *host) | |||
140 | overlapping_strcpy(scope, cp); | 140 | overlapping_strcpy(scope, cp); |
141 | } | 141 | } |
142 | 142 | ||
143 | #if 0 /* were needed when we used signal-driven progress bar */ | ||
144 | /* Read NMEMB bytes into PTR from STREAM. Returns the number of bytes read, | ||
145 | * and a short count if an eof or non-interrupt error is encountered. */ | ||
146 | static size_t safe_fread(void *ptr, size_t nmemb, FILE *stream) | ||
147 | { | ||
148 | size_t ret; | ||
149 | char *p = (char*)ptr; | ||
150 | |||
151 | do { | ||
152 | clearerr(stream); | ||
153 | errno = 0; | ||
154 | ret = fread(p, 1, nmemb, stream); | ||
155 | p += ret; | ||
156 | nmemb -= ret; | ||
157 | } while (nmemb && ferror(stream) && errno == EINTR); | ||
158 | |||
159 | return p - (char*)ptr; | ||
160 | } | ||
161 | |||
162 | /* Read a line or SIZE-1 bytes into S, whichever is less, from STREAM. | ||
163 | * Returns S, or NULL if an eof or non-interrupt error is encountered. */ | ||
164 | static char *safe_fgets(char *s, int size, FILE *stream) | ||
165 | { | ||
166 | char *ret; | ||
167 | |||
168 | do { | ||
169 | clearerr(stream); | ||
170 | errno = 0; | ||
171 | ret = fgets(s, size, stream); | ||
172 | } while (ret == NULL && ferror(stream) && errno == EINTR); | ||
173 | |||
174 | return ret; | ||
175 | } | ||
176 | #endif | ||
177 | |||
178 | #if ENABLE_FEATURE_WGET_AUTHENTICATION | 143 | #if ENABLE_FEATURE_WGET_AUTHENTICATION |
179 | /* Base64-encode character string. */ | 144 | /* Base64-encode character string. */ |
180 | static char *base64enc(const char *str) | 145 | static char *base64enc(const char *str) |
@@ -631,7 +596,7 @@ static int download_one_url(const char *url) | |||
631 | /* If there was no -O FILE, guess output filename */ | 596 | /* If there was no -O FILE, guess output filename */ |
632 | output_fd = -1; | 597 | output_fd = -1; |
633 | fname_out_alloc = NULL; | 598 | fname_out_alloc = NULL; |
634 | if (!G.fname_out) { | 599 | if (!(option_mask32 & WGET_OPT_OUTNAME)) { |
635 | G.fname_out = bb_get_last_path_component_nostrip(target.path); | 600 | G.fname_out = bb_get_last_path_component_nostrip(target.path); |
636 | /* handle "wget http://kernel.org//" */ | 601 | /* handle "wget http://kernel.org//" */ |
637 | if (G.fname_out[0] == '/' || !G.fname_out[0]) | 602 | if (G.fname_out[0] == '/' || !G.fname_out[0]) |
@@ -865,28 +830,19 @@ However, in real world it was observed that some web servers | |||
865 | } | 830 | } |
866 | 831 | ||
867 | free(lsa); | 832 | free(lsa); |
868 | free(server.allocated); | ||
869 | free(target.allocated); | ||
870 | |||
871 | if (option_mask32 & WGET_OPT_SPIDER) { | ||
872 | free(fname_out_alloc); | ||
873 | fclose(sfp); | ||
874 | return EXIT_SUCCESS; | ||
875 | } | ||
876 | 833 | ||
877 | if (output_fd < 0) { | 834 | if (!(option_mask32 & WGET_OPT_SPIDER)) { |
878 | int o_flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL; | 835 | if (output_fd < 0) { |
879 | /* compat with wget: -O FILE can overwrite */ | 836 | int o_flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL; |
880 | if (option_mask32 & WGET_OPT_OUTNAME) | 837 | /* compat with wget: -O FILE can overwrite */ |
881 | o_flags = O_WRONLY | O_CREAT | O_TRUNC; | 838 | if (option_mask32 & WGET_OPT_OUTNAME) |
882 | output_fd = xopen(G.fname_out, o_flags); | 839 | o_flags = O_WRONLY | O_CREAT | O_TRUNC; |
840 | output_fd = xopen(G.fname_out, o_flags); | ||
841 | } | ||
842 | retrieve_file_data(dfp, output_fd); | ||
843 | xclose(output_fd); | ||
883 | } | 844 | } |
884 | 845 | ||
885 | free(fname_out_alloc); | ||
886 | |||
887 | retrieve_file_data(dfp, output_fd); | ||
888 | xclose(output_fd); | ||
889 | |||
890 | if (dfp != sfp) { | 846 | if (dfp != sfp) { |
891 | /* It's ftp. Close data connection properly */ | 847 | /* It's ftp. Close data connection properly */ |
892 | fclose(dfp); | 848 | fclose(dfp); |
@@ -896,6 +852,10 @@ However, in real world it was observed that some web servers | |||
896 | } | 852 | } |
897 | fclose(sfp); | 853 | fclose(sfp); |
898 | 854 | ||
855 | free(server.allocated); | ||
856 | free(target.allocated); | ||
857 | free(fname_out_alloc); | ||
858 | |||
899 | return EXIT_SUCCESS; | 859 | return EXIT_SUCCESS; |
900 | } | 860 | } |
901 | 861 | ||