diff options
author | Rob Landley <rob@landley.net> | 2013-10-31 22:22:21 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2013-10-31 22:22:21 -0500 |
commit | 07c4c66ba4e4ad7e17a5308dc3a2f8c5bcffb0c6 (patch) | |
tree | e08a41087ee81e1551623638f4e44f79cc554a52 /toys/posix/xargs.c | |
parent | 6f6ccc189d4574e257687d982d24d1e35934d77d (diff) | |
download | toybox-07c4c66ba4e4ad7e17a5308dc3a2f8c5bcffb0c6.tar.gz |
Patch from William Haddon to make xargs with blank input call its command line once. (Tweaked slightly for whitespace and to collate variable declarations.)
Diffstat (limited to 'toys/posix/xargs.c')
-rw-r--r-- | toys/posix/xargs.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/toys/posix/xargs.c b/toys/posix/xargs.c index e1611ec3..b024789f 100644 --- a/toys/posix/xargs.c +++ b/toys/posix/xargs.c @@ -106,9 +106,9 @@ static char *handle_entries(char *data, char **entry) void xargs_main(void) { - struct double_list *dlist = NULL; + struct double_list *dlist = NULL, *dtemp; int entries, bytes, done = 0, status; - char *data = NULL; + char *data = NULL, **out; if (!(toys.optflags & FLAG_0)) TT.delim = '\n'; @@ -124,8 +124,6 @@ void xargs_main(void) // Loop through exec chunks. while (data || !done) { - char **out; - TT.entries = 0; TT.bytes = bytes; @@ -160,17 +158,14 @@ void xargs_main(void) if (data && !TT.entries) error_exit("argument too long"); out = xzalloc((entries+TT.entries+1)*sizeof(char *)); - if (dlist) { - struct double_list *dtemp; + // Fill out command line to exec + memcpy(out, toys.optargs, entries*sizeof(char *)); + TT.entries = 0; + TT.bytes = bytes; + if (dlist) dlist->prev->next = 0; + for (dtemp = dlist; dtemp; dtemp = dtemp->next) + handle_entries(dtemp->data, out+entries); - // Fill out command line to exec - memcpy(out, toys.optargs, entries*sizeof(char *)); - TT.entries = 0; - TT.bytes = bytes; - dlist->prev->next = 0; - for (dtemp = dlist; dtemp; dtemp = dtemp->next) - handle_entries(dtemp->data, out+entries); - } pid_t pid=fork(); if (!pid) { xclose(0); |