aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-02-13 02:49:43 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-02-13 02:49:43 +0100
commit9a5b7f636dad35ac84056768b3669bdca02d2700 (patch)
tree3d58d614fd30709c355b8455edc216eb5054c64a /networking
parenta3661096f2e8b49f66ce6c9bba71aa01b79098e2 (diff)
downloadbusybox-9a5b7f636dad35ac84056768b3669bdca02d2700.tar.gz
wget: support multiple URLs on command line even without -O :)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r--networking/wget.c70
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)
overlapping_strcpy(scope, cp);
}
-#if 0 /* were needed when we used signal-driven progress bar */
-/* Read NMEMB bytes into PTR from STREAM. Returns the number of bytes read,
- * and a short count if an eof or non-interrupt error is encountered. */
-static size_t safe_fread(void *ptr, size_t nmemb, FILE *stream)
-{
- size_t ret;
- char *p = (char*)ptr;
-
- do {
- clearerr(stream);
- errno = 0;
- ret = fread(p, 1, nmemb, stream);
- p += ret;
- nmemb -= ret;
- } while (nmemb && ferror(stream) && errno == EINTR);
-
- return p - (char*)ptr;
-}
-
-/* Read a line or SIZE-1 bytes into S, whichever is less, from STREAM.
- * Returns S, or NULL if an eof or non-interrupt error is encountered. */
-static char *safe_fgets(char *s, int size, FILE *stream)
-{
- char *ret;
-
- do {
- clearerr(stream);
- errno = 0;
- ret = fgets(s, size, stream);
- } while (ret == NULL && ferror(stream) && errno == EINTR);
-
- return ret;
-}
-#endif
-
#if ENABLE_FEATURE_WGET_AUTHENTICATION
/* Base64-encode character string. */
static char *base64enc(const char *str)
@@ -631,7 +596,7 @@ static int download_one_url(const char *url)
/* If there was no -O FILE, guess output filename */
output_fd = -1;
fname_out_alloc = NULL;
- if (!G.fname_out) {
+ if (!(option_mask32 & WGET_OPT_OUTNAME)) {
G.fname_out = bb_get_last_path_component_nostrip(target.path);
/* handle "wget http://kernel.org//" */
if (G.fname_out[0] == '/' || !G.fname_out[0])
@@ -865,28 +830,19 @@ However, in real world it was observed that some web servers
}
free(lsa);
- free(server.allocated);
- free(target.allocated);
-
- if (option_mask32 & WGET_OPT_SPIDER) {
- free(fname_out_alloc);
- fclose(sfp);
- return EXIT_SUCCESS;
- }
- if (output_fd < 0) {
- int o_flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL;
- /* compat with wget: -O FILE can overwrite */
- if (option_mask32 & WGET_OPT_OUTNAME)
- o_flags = O_WRONLY | O_CREAT | O_TRUNC;
- output_fd = xopen(G.fname_out, o_flags);
+ if (!(option_mask32 & WGET_OPT_SPIDER)) {
+ if (output_fd < 0) {
+ int o_flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL;
+ /* compat with wget: -O FILE can overwrite */
+ if (option_mask32 & WGET_OPT_OUTNAME)
+ o_flags = O_WRONLY | O_CREAT | O_TRUNC;
+ output_fd = xopen(G.fname_out, o_flags);
+ }
+ retrieve_file_data(dfp, output_fd);
+ xclose(output_fd);
}
- free(fname_out_alloc);
-
- retrieve_file_data(dfp, output_fd);
- xclose(output_fd);
-
if (dfp != sfp) {
/* It's ftp. Close data connection properly */
fclose(dfp);
@@ -896,6 +852,10 @@ However, in real world it was observed that some web servers
}
fclose(sfp);
+ free(server.allocated);
+ free(target.allocated);
+ free(fname_out_alloc);
+
return EXIT_SUCCESS;
}