From 2fd8a74dcae1cd01879a3e9a733d798bb386dc16 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 19 Mar 2015 13:57:02 -0500 Subject: Add -123 support to head (suggested by Elliott Hughes). --- toys/posix/head.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'toys/posix') diff --git a/toys/posix/head.c b/toys/posix/head.c index e8517d44..42f945bf 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,12 @@ static void do_head(int fd, char *name) void head_main(void) { - loopfiles(toys.optargs, do_head); + char *arg = *toys.optargs; + + // handle old "-42" style arguments + if (arg && *arg == '-' && arg[1]) { + TT.lines = atolx(arg+1); + toys.optc--; + } + loopfiles(toys.optargs+!!arg, do_head); } -- cgit v1.2.3