Robin Farine writes:
[oweals/busybox.git] / networking / wget.c
index cb0790ea781b27892d7f183e753688dfaa663f05..e233daf050748122532525c0100a9b3cf3ee9460 100644 (file)
@@ -55,7 +55,7 @@ static volatile unsigned long statbytes = 0; /* Number of bytes transferred so f
 /* For progressmeter() -- number of seconds before xfer considered "stalled" */
 static const int STALLTIME = 5;
 #endif
-               
+
 static void close_and_delete_outfile(FILE* output, char *fname_out, int do_continue)
 {
        if (output != stdout && do_continue==0) {
@@ -236,18 +236,18 @@ int wget_main(int argc, char **argv)
                        use_proxy = 0;
                }
        }
-       
+
        /* Guess an output filename */
        if (!fname_out) {
-               fname_out = 
+               fname_out =
 #ifdef CONFIG_FEATURE_WGET_STATUSBAR
-                       curfile = 
+                       curfile =
 #endif
                        bb_get_last_path_component(target.path);
                if (fname_out==NULL || strlen(fname_out)<1) {
-                       fname_out = 
+                       fname_out =
 #ifdef CONFIG_FEATURE_WGET_STATUSBAR
-                               curfile = 
+                               curfile =
 #endif
                                "index.html";
                }
@@ -309,7 +309,7 @@ int wget_main(int argc, char **argv)
                         */
                        if (sfp) fclose(sfp);
                        sfp = open_socket(&s_in);
-                       
+
                        /*
                         * Send HTTP request.
                         */
@@ -351,7 +351,7 @@ int wget_main(int argc, char **argv)
 read_response:
                        if (fgets(buf, sizeof(buf), sfp) == NULL)
                                close_delete_and_die("no response from server");
-                               
+
                        for (s = buf ; *s != '\0' && !isspace(*s) ; ++s)
                        ;
                        for ( ; isspace(*s) ; ++s)
@@ -379,7 +379,7 @@ read_response:
                                        chomp(buf);
                                        close_delete_and_die("server returned error %d: %s", atoi(s), buf);
                        }
-               
+
                        /*
                         * Retrieve HTTP headers.
                         */
@@ -416,7 +416,7 @@ read_response:
                                }
                        }
                } while(status >= 300);
-               
+
                dfp = sfp;
        }
        else
@@ -431,7 +431,7 @@ read_response:
                if (ftpcmd(NULL, NULL, sfp, buf) != 220)
                        close_delete_and_die("%s", buf+4);
 
-               /* 
+               /*
                 * Splitting username:password pair,
                 * trying to log in
                 */
@@ -448,10 +448,10 @@ read_response:
                        default:
                                close_delete_and_die("ftp login: %s", buf+4);
                }
-               
+
                ftpcmd("CDUP", NULL, sfp, buf);
                ftpcmd("TYPE I", NULL, sfp, buf);
-               
+
                /*
                 * Querying file size
                 */
@@ -463,7 +463,7 @@ read_response:
                        filesize = value;
                        got_clen = 1;
                }
-               
+
                /*
                 * Entering passive mode
                 */
@@ -486,7 +486,7 @@ read_response:
                        } else
                                filesize -= beg_range;
                }
-               
+
                if (ftpcmd("RETR /", target.path, sfp, buf) > 150)
                        close_delete_and_die("RETR: %s", buf+4);
 
@@ -660,28 +660,32 @@ 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);
                fflush(fp);
        }
-       
+
        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);
 }
 
 #ifdef CONFIG_FEATURE_WGET_STATUSBAR
-/* Stuff below is from BSD rcp util.c, as added to openshh. 
+/* Stuff below is from BSD rcp util.c, as added to openshh.
  * Original copyright notice is retained at the end of this file.
- * 
- */ 
+ *
+ */
 
 
 static int
@@ -794,7 +798,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,8 +816,8 @@ 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
  *     The Regents of the University of California.  All rights reserved.
@@ -827,8 +831,8 @@ progressmeter(int flag)
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  *
- * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change 
- *             ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change> 
+ * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
+ *             ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
  *
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
@@ -846,7 +850,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.70 2004/03/06 22:11:44 andersen Exp $
+ *     $Id: wget.c,v 1.74 2004/04/14 17:51:24 andersen Exp $
  */