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;
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);
}
/* 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);
}
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 */
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)
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 */
/* 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>
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");
}
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);
/* 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>
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");
}
/*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);
}
* 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 $
*/
}
/* 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);
}
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;
}
#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:
/*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);
}
* 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 $
*/
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)