changeset 1102:e1f30cbf79f9 draft

Patch from William Haddon to make xargs with blank input call its command line once. (Tweaked slightly for whitespace and to collate variable declarations.)
author Rob Landley <rob@landley.net>
date Thu, 31 Oct 2013 22:22:21 -0500
parents ccf4193167c3
children bc09fa708d94
files toys/posix/xargs.c
diffstat 1 files changed, 9 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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);