aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-03-19 13:57:02 -0500
committerRob Landley <rob@landley.net>2015-03-19 13:57:02 -0500
commit2fd8a74dcae1cd01879a3e9a733d798bb386dc16 (patch)
tree7204712708cc10dc1d6781096eaaec8eb0dee43b /toys
parent893a092f62a6652ec9668e1e0fc68910dedc2acc (diff)
downloadtoybox-2fd8a74dcae1cd01879a3e9a733d798bb386dc16.tar.gz
Add -123 support to head (suggested by Elliott Hughes).
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/head.c11
1 files changed, 9 insertions, 2 deletions
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);
}