sysctl was seriously broken. And since in some cases 'CONFIG_SYSCTL'
[oweals/busybox.git] / networking / wget.c
index 619c138baff3e451c9ad52f558e2533a5bbea7f8..0a4ccaddd0b24092b6be78c5f0c5fb32c9552df3 100644 (file)
@@ -117,9 +117,9 @@ static char *safe_fgets(char *s, int size, FILE *stream)
 /*
  *  Base64-encode character string
  *  oops... isn't something similar in uuencode.c?
- *  It would be better to use already existing code
+ *  XXX: It would be better to use already existing code
  */
-char *base64enc(unsigned char *p, char *buf, int len) {
+static char *base64enc(unsigned char *p, char *buf, int len) {
 
         char al[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
                     "0123456789+/";
@@ -191,7 +191,7 @@ int wget_main(int argc, char **argv)
        /*
         * Crack command line.
         */
-       bb_opt_complementaly = "\203*";
+       bb_opt_complementally = "\203*";
        bb_applet_long_options = wget_long_options;
        opt = bb_getopt_ulflags(argc, argv, "cq\213O:\203:P:Y:", &fname_out, &headers_llist, &dir_prefix, &proxy_flag);
        if (opt & WGET_OPT_CONTINUE) {
@@ -239,11 +239,15 @@ int wget_main(int argc, char **argv)
 
        /* Guess an output filename */
        if (!fname_out) {
-               fname_out =
+               // Dirty hack. Needed because bb_get_last_path_component
+               // will destroy trailing / by storing '\0' in last byte!
+               if(target.path[strlen(target.path)-1]!='/') {
+                       fname_out =
 #ifdef CONFIG_FEATURE_WGET_STATUSBAR
-                       curfile =
+                               curfile =
 #endif
-                       bb_get_last_path_component(target.path);
+                               bb_get_last_path_component(target.path);
+               }
                if (fname_out==NULL || strlen(fname_out)<1) {
                        fname_out =
 #ifdef CONFIG_FEATURE_WGET_STATUSBAR
@@ -660,8 +664,6 @@ char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
 
 static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf)
 {
-       char *p;
-
        if (s1) {
                if (!s2) s2="";
                fprintf(fp, "%s%s\r\n", s1, s2);
@@ -669,9 +671,15 @@ static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf)
        }
 
        do {
-               p = fgets(buf, 510, fp);
-               if (!p)
+               char *buf_ptr;
+
+               if (fgets(buf, 510, fp) == NULL) {
                        bb_perror_msg_and_die("fgets()");
+               }
+               buf_ptr = strstr(buf, "\r\n");
+               if (buf_ptr) {
+                       *buf_ptr = '\0';
+               }
        } while (! isdigit(buf[0]) || buf[3] != ' ');
 
        return atoi(buf);
@@ -794,7 +802,7 @@ progressmeter(int flag)
                snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
                         "%02d:%02d ETA", i / 60, i % 60);
        }
-       write(fileno(stderr), buf, strlen(buf));
+       write(STDERR_FILENO, buf, strlen(buf));
 
        if (flag == -1) {
                struct sigaction sa;
@@ -812,7 +820,7 @@ progressmeter(int flag)
 #endif
 
 /* Original copyright notice which applies to the CONFIG_FEATURE_WGET_STATUSBAR stuff,
- * much of which was blatently stolen from openssh.  */
+ * much of which was blatantly stolen from openssh.  */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -846,7 +854,7 @@ progressmeter(int flag)
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     $Id: wget.c,v 1.71 2004/03/15 08:28:53 andersen Exp $
+ *     $Id: wget.c,v 1.75 2004/10/08 08:27:40 andersen Exp $
  */