On Mon, Mar 16, 2015 at 09:16:00PM -0700, enh wrote: > Allow "head -X" as well as "head -n X". > > diff --git a/toys/posix/head.c b/toys/posix/head.c > index e8517d4..608b93a 100644 > --- a/toys/posix/head.c > +++ b/toys/posix/head.c > @@ -4,7 +4,7 @@ > * > * See http://opengroup.org/onlinepubs/9699919799/utilities/head.html > > -USE_HEAD(NEWTOY(head, "n#<0=10", TOYFLAG_BIN)) > +USE_HEAD(NEWTOY(head, "?n#<0=10", TOYFLAG_BIN)) > > config HEAD > bool "head" > @@ -50,5 +50,10 @@ static void do_head(int fd, char *name) > > void head_main(void) > { > - loopfiles(toys.optargs, do_head); > + char **args = toys.optargs; > + if (*args && **args == '-') { > + TT.lines = xstrtol(*(args++) + 1, NULL, 10);
This will break "head -", which is valid though redundant. I'd suggest using if (*args && **args == '-' && isdigit(*args + 1)) or some similar check. Same applies to the "tail -X" patch. > + toys.optc--; > + } > + loopfiles(args, do_head); > } > _______________________________________________ > Toybox mailing list > [email protected] > http://lists.landley.net/listinfo.cgi/toybox-landley.net _______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
