diff options
author | Matt Kraai | 2001-02-01 16:49:30 +0000 |
---|---|---|
committer | Matt Kraai | 2001-02-01 16:49:30 +0000 |
commit | 05e782ddd3dc58245c889529bb8aeeaddf24bf71 (patch) | |
tree | 8fbb91ca75358923724889a558c954cffdf10136 | |
parent | bd018b1babf0521b8e740abb6473133c1c4c35d2 (diff) | |
download | busybox-05e782ddd3dc58245c889529bb8aeeaddf24bf71.zip busybox-05e782ddd3dc58245c889529bb8aeeaddf24bf71.tar.gz |
Fix wget error message and add (and use) chomp library function.
-rw-r--r-- | archival/tar.c | 3 | ||||
-rw-r--r-- | busybox.h | 1 | ||||
-rw-r--r-- | editors/sed.c | 3 | ||||
-rw-r--r-- | findutils/grep.c | 3 | ||||
-rw-r--r-- | findutils/xargs.c | 3 | ||||
-rw-r--r-- | grep.c | 3 | ||||
-rw-r--r-- | hostname.c | 5 | ||||
-rw-r--r-- | include/busybox.h | 1 | ||||
-rw-r--r-- | networking/hostname.c | 5 | ||||
-rw-r--r-- | networking/wget.c | 3 | ||||
-rw-r--r-- | sed.c | 3 | ||||
-rw-r--r-- | tar.c | 3 | ||||
-rw-r--r-- | utility.c | 13 | ||||
-rw-r--r-- | wget.c | 3 | ||||
-rw-r--r-- | xargs.c | 3 |
15 files changed, 31 insertions, 24 deletions
diff --git a/archival/tar.c b/archival/tar.c index 60744e8..fb0fcc6 100644 --- a/archival/tar.c +++ b/archival/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; @@ -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); diff --git a/editors/sed.c b/editors/sed.c index e0351c3..0ce9f45 100644 --- a/editors/sed.c +++ b/editors/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/findutils/grep.c b/findutils/grep.c index 320655b..fec8d09 100644 --- a/findutils/grep.c +++ b/findutils/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(®ex, line, 0, NULL, 0); if (ret == 0 && !invert_search) { /* match */ diff --git a/findutils/xargs.c b/findutils/xargs.c index 89bcfc1..f05efd9 100644 --- a/findutils/xargs.c +++ b/findutils/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) @@ -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(®ex, line, 0, NULL, 0); if (ret == 0 && !invert_search) { /* match */ @@ -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"); } diff --git a/include/busybox.h b/include/busybox.h index 5f9425a..e332ed4 100644 --- a/include/busybox.h +++ b/include/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); diff --git a/networking/hostname.c b/networking/hostname.c index 3dba641..ce17ba9 100644 --- a/networking/hostname.c +++ b/networking/hostname.c @@ -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"); } diff --git a/networking/wget.c b/networking/wget.c index 70f8d1b..c134427 100644 --- a/networking/wget.c +++ b/networking/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 $ */ @@ -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); } @@ -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; @@ -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: @@ -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 $ */ @@ -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) |