Mercurial > hg > toybox
changeset 525:f188e572acc7
Fix xargs -0 option.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 05 Mar 2012 20:48:35 -0600 |
parents | 2247cdb73f2d |
children | f435e8e3a0ba |
files | toys/xargs.c |
diffstat | 1 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/toys/xargs.c Mon Mar 05 00:25:32 2012 +0100 +++ b/toys/xargs.c Mon Mar 05 20:48:35 2012 -0600 @@ -66,7 +66,7 @@ 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 @@ if (entry) entry[TT.entries] = save; ++TT.entries; } + + // -0 support } else { + 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.bytes += strlen(data); - if (TT.bytes >= TT.max_bytes || ++TT.entries >= TT.max_entries) - return (char *)1; + TT.entries++; } return NULL; @@ -106,8 +110,8 @@ // 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++)