diff options
author | Rob Landley <rob@landley.net> | 2012-03-05 20:48:35 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2012-03-05 20:48:35 -0600 |
commit | 4250d52c84c8055525b14ce3687bffc52d6300ad (patch) | |
tree | ea71504c083e61322538a2e76dec54b996b729d3 /toys/xargs.c | |
parent | e2aa5cb7a63fffeb8170d084f9c220427ed5ff4b (diff) | |
download | toybox-4250d52c84c8055525b14ce3687bffc52d6300ad.tar.gz |
Fix xargs -0 option.
Diffstat (limited to 'toys/xargs.c')
-rw-r--r-- | toys/xargs.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/toys/xargs.c b/toys/xargs.c index 830fdaf6..0d513253 100644 --- a/toys/xargs.c +++ b/toys/xargs.c @@ -66,7 +66,7 @@ static char *handle_entries(char *data, char **entry) s++; } - if (TT.entries >= TT.max_entries && TT.max_entries) + if (TT.max_entries && TT.entries >= TT.max_entries) return *s ? s : (char *)1; if (!*s) break; @@ -85,11 +85,15 @@ static char *handle_entries(char *data, char **entry) if (entry) entry[TT.entries] = save; ++TT.entries; } + + // -0 support } else { - if (entry) entry[TT.entries] = data; - TT.bytes += strlen(data); - if (TT.bytes >= TT.max_bytes || ++TT.entries >= TT.max_entries) + TT.bytes += strlen(data)+1; + if (TT.max_bytes && TT.bytes >= TT.max_bytes) return data; + if (TT.max_entries && TT.entries >= TT.max_entries) return (char *)1; + if (entry) entry[TT.entries] = data; + TT.entries++; } return NULL; @@ -106,8 +110,8 @@ void xargs_main(void) // If no optargs, call echo. if (!toys.optc) { free(toys.optargs); - *(toys.optargs=xzalloc(2*sizeof(char *)))="echo"; - toys.optc=1; + *(toys.optargs = xzalloc(2*sizeof(char *)))="echo"; + toys.optc = 1; } for (entries = 0, bytes = -1; entries < toys.optc; entries++, bytes++) |