Fix wget error message and add (and use) chomp library function.
authorMatt Kraai <kraai@debian.org>
Thu, 1 Feb 2001 16:49:30 +0000 (16:49 -0000)
committerMatt Kraai <kraai@debian.org>
Thu, 1 Feb 2001 16:49:30 +0000 (16:49 -0000)
15 files changed:
archival/tar.c
busybox.h
editors/sed.c
findutils/grep.c
findutils/xargs.c
grep.c
hostname.c
include/busybox.h
networking/hostname.c
networking/wget.c
sed.c
tar.c
utility.c
wget.c
xargs.c

index 60744e8db91740256fc37398f8616375165305d6..fb0fcc614dce0f987db583c943c99104d315ee2c 100644 (file)
@@ -274,8 +274,7 @@ extern int tar_main(int argc, char **argv)
                                while (fgets(file, sizeof(file), fileList) != NULL) {
                                        excludeList = xrealloc(excludeList,
                                                        sizeof(char *) * (excludeListSize+2));
-                                       if (file[strlen(file)-1] == '\n')
-                                               file[strlen(file)-1] = '\0';
+                                       chomp(file);
                                        excludeList[excludeListSize] = xstrdup(file);
                                        /* Tack a NULL onto the end of the list */
                                        excludeList[++excludeListSize] = NULL;
index 5f9425a5bf28513b9e34af79d243ff38d7549bb9..e332ed41282a31db92c2a6e1dfff7b09adc73965 100644 (file)
--- a/busybox.h
+++ b/busybox.h
@@ -152,6 +152,7 @@ extern char process_escape_sequence(char **ptr);
 extern char *get_last_path_component(char *path);
 extern FILE *wfopen(const char *path, const char *mode);
 extern FILE *xfopen(const char *path, const char *mode);
+extern void chomp(char *s);
 
 #ifndef DMALLOC
 extern void *xmalloc (size_t size);
index e0351c3b80f6ae3029b68a4450467728a26dbc4d..0ce9f45e0b527cf6e62e3f6bd73a58dcbf06d94c 100644 (file)
@@ -436,8 +436,7 @@ static void load_cmd_file(char *filename)
                }
                /* eat trailing newline (if any) --if I don't do this, edit commands
                 * (aic) will print an extra newline */
-               if (line[strlen(line)-1] == '\n')
-                       line[strlen(line)-1] = 0;
+               chomp(line);
                add_cmd_str(line);
                free(line);
        }
index 320655bf4eb71b1c17f32a6d1d642c40acec9890..fec8d0913c7dafc4e2b6248a6ac567557b475ad5 100644 (file)
@@ -69,8 +69,7 @@ static void grep_file(FILE *file)
        int nmatches = 0;
 
        while ((line = get_line_from_file(file)) != NULL) {
-               if (line[strlen(line)-1] == '\n')
-                       line[strlen(line)-1] = '\0';
+               chomp(line);
                linenum++;
                ret = regexec(&regex, line, 0, NULL, 0);
                if (ret == 0 && !invert_search) { /* match */
index 89bcfc156d1f4de04508752dd4928c6e04d06723..f05efd917263be560823a27ae217c7e8060950ff 100644 (file)
@@ -68,8 +68,7 @@ int xargs_main(int argc, char **argv)
                char *execstr = NULL;
 
                /* eat the newline off the filename. */
-               if (file_to_act_on[strlen(file_to_act_on)-1] == '\n')
-                       file_to_act_on[strlen(file_to_act_on)-1] = '\0';
+               chomp(file_to_act_on);
 
                /* eat blank lines */
                if (strlen(file_to_act_on) == 0)
diff --git a/grep.c b/grep.c
index 320655bf4eb71b1c17f32a6d1d642c40acec9890..fec8d0913c7dafc4e2b6248a6ac567557b475ad5 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -69,8 +69,7 @@ static void grep_file(FILE *file)
        int nmatches = 0;
 
        while ((line = get_line_from_file(file)) != NULL) {
-               if (line[strlen(line)-1] == '\n')
-                       line[strlen(line)-1] = '\0';
+               chomp(line);
                linenum++;
                ret = regexec(&regex, line, 0, NULL, 0);
                if (ret == 0 && !invert_search) { /* match */
index 3dba641540e2c8da76c6fedfae5e189a7ed7a9a6..ce17ba91cb751a301cadbf7ce3d5dc099ee01b7f 100644 (file)
@@ -1,6 +1,6 @@
 /* vi: set sw=4 ts=4: */
 /*
- * $Id: hostname.c,v 1.22 2001/01/31 19:00:20 kraai Exp $
+ * $Id: hostname.c,v 1.23 2001/02/01 16:49:29 kraai Exp $
  * Mini hostname implementation for busybox
  *
  * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -49,8 +49,7 @@ void do_sethostname(char *s, int isfile)
                f = xfopen(s, "r");
                fgets(buf, 255, f);
                fclose(f);
-               if (buf[strlen(buf) - 1] == '\n')
-                       buf[strlen(buf) - 1] = 0;
+               chomp(buf);
                if (sethostname(buf, strlen(buf)) < 0)
                        perror_msg_and_die("sethostname");
        }
index 5f9425a5bf28513b9e34af79d243ff38d7549bb9..e332ed41282a31db92c2a6e1dfff7b09adc73965 100644 (file)
@@ -152,6 +152,7 @@ extern char process_escape_sequence(char **ptr);
 extern char *get_last_path_component(char *path);
 extern FILE *wfopen(const char *path, const char *mode);
 extern FILE *xfopen(const char *path, const char *mode);
+extern void chomp(char *s);
 
 #ifndef DMALLOC
 extern void *xmalloc (size_t size);
index 3dba641540e2c8da76c6fedfae5e189a7ed7a9a6..ce17ba91cb751a301cadbf7ce3d5dc099ee01b7f 100644 (file)
@@ -1,6 +1,6 @@
 /* vi: set sw=4 ts=4: */
 /*
- * $Id: hostname.c,v 1.22 2001/01/31 19:00:20 kraai Exp $
+ * $Id: hostname.c,v 1.23 2001/02/01 16:49:29 kraai Exp $
  * Mini hostname implementation for busybox
  *
  * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -49,8 +49,7 @@ void do_sethostname(char *s, int isfile)
                f = xfopen(s, "r");
                fgets(buf, 255, f);
                fclose(f);
-               if (buf[strlen(buf) - 1] == '\n')
-                       buf[strlen(buf) - 1] = 0;
+               chomp(buf);
                if (sethostname(buf, strlen(buf)) < 0)
                        perror_msg_and_die("sethostname");
        }
index 70f8d1b89bb0f021b5ed84a3e4fac5992417362a..c134427e44e78700b1793651b584883e41b847f6 100644 (file)
@@ -216,6 +216,7 @@ int wget_main(int argc, char **argv)
                        /*FALLTHRU*/
                default:
                        close_and_delete_outfile(output, fname_out, do_continue);
+                       chomp(buf);
                        error_msg_and_die("server returned error %d: %s", atoi(s), buf);
        }
 
@@ -532,7 +533,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.25 2001/01/31 19:00:21 kraai Exp $
+ *     $Id: wget.c,v 1.26 2001/02/01 16:49:30 kraai Exp $
  */
 
 
diff --git a/sed.c b/sed.c
index e0351c3b80f6ae3029b68a4450467728a26dbc4d..0ce9f45e0b527cf6e62e3f6bd73a58dcbf06d94c 100644 (file)
--- a/sed.c
+++ b/sed.c
@@ -436,8 +436,7 @@ static void load_cmd_file(char *filename)
                }
                /* eat trailing newline (if any) --if I don't do this, edit commands
                 * (aic) will print an extra newline */
-               if (line[strlen(line)-1] == '\n')
-                       line[strlen(line)-1] = 0;
+               chomp(line);
                add_cmd_str(line);
                free(line);
        }
diff --git a/tar.c b/tar.c
index 60744e8db91740256fc37398f8616375165305d6..fb0fcc614dce0f987db583c943c99104d315ee2c 100644 (file)
--- a/tar.c
+++ b/tar.c
@@ -274,8 +274,7 @@ extern int tar_main(int argc, char **argv)
                                while (fgets(file, sizeof(file), fileList) != NULL) {
                                        excludeList = xrealloc(excludeList,
                                                        sizeof(char *) * (excludeListSize+2));
-                                       if (file[strlen(file)-1] == '\n')
-                                               file[strlen(file)-1] = '\0';
+                                       chomp(file);
                                        excludeList[excludeListSize] = xstrdup(file);
                                        /* Tack a NULL onto the end of the list */
                                        excludeList[++excludeListSize] = NULL;
index 31192693872f238c2200b6a87bc4e9766967b9d7..0a0e652affb8ab6b9f75de0f21807ab64debd7c1 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -1760,6 +1760,19 @@ char *format(unsigned long val, unsigned long hr)
 }
 #endif
 
+#if defined(BB_GREP) || defined(BB_HOSTNAME) || defined(BB_SED) || defined(BB_TAR) || defined(BB_WGET) || defined(BB_XARGS)
+void chomp(char *s)
+{
+       size_t len = strlen(s);
+
+       if (len == 0)
+               return;
+
+       if (s[len-1] == '\n')
+               s[len-1] = '\0';
+}
+#endif
+
 /* END CODE */
 /*
 Local Variables:
diff --git a/wget.c b/wget.c
index 70f8d1b89bb0f021b5ed84a3e4fac5992417362a..c134427e44e78700b1793651b584883e41b847f6 100644 (file)
--- a/wget.c
+++ b/wget.c
@@ -216,6 +216,7 @@ int wget_main(int argc, char **argv)
                        /*FALLTHRU*/
                default:
                        close_and_delete_outfile(output, fname_out, do_continue);
+                       chomp(buf);
                        error_msg_and_die("server returned error %d: %s", atoi(s), buf);
        }
 
@@ -532,7 +533,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.25 2001/01/31 19:00:21 kraai Exp $
+ *     $Id: wget.c,v 1.26 2001/02/01 16:49:30 kraai Exp $
  */
 
 
diff --git a/xargs.c b/xargs.c
index 89bcfc156d1f4de04508752dd4928c6e04d06723..f05efd917263be560823a27ae217c7e8060950ff 100644 (file)
--- a/xargs.c
+++ b/xargs.c
@@ -68,8 +68,7 @@ int xargs_main(int argc, char **argv)
                char *execstr = NULL;
 
                /* eat the newline off the filename. */
-               if (file_to_act_on[strlen(file_to_act_on)-1] == '\n')
-                       file_to_act_on[strlen(file_to_act_on)-1] = '\0';
+               chomp(file_to_act_on);
 
                /* eat blank lines */
                if (strlen(file_to_act_on) == 0)