# HG changeset patch # User Rob Landley # Date 1383276141 18000 # Node ID e1f30cbf79f9ab120546159ef4f46b89619f78de # Parent ccf4193167c390345b3b211dcba8557a042f942d Patch from William Haddon to make xargs with blank input call its command line once. (Tweaked slightly for whitespace and to collate variable declarations.) diff -r ccf4193167c3 -r e1f30cbf79f9 toys/posix/xargs.c --- a/toys/posix/xargs.c Thu Oct 31 09:36:55 2013 -0500 +++ b/toys/posix/xargs.c Thu Oct 31 22:22:21 2013 -0500 @@ -106,9 +106,9 @@ 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 @@ // Loop through exec chunks. while (data || !done) { - char **out; - TT.entries = 0; TT.bytes = bytes; @@ -160,17 +158,14 @@ 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);