changeset 1744:0c30e5484516

Add -123 support to head (suggested by Elliott Hughes).
author Rob Landley <rob@landley.net>
date Thu, 19 Mar 2015 13:57:02 -0500
parents da1296acc73e
children 1b97da3c7b91
files toys/posix/head.c
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/toys/posix/head.c	Wed Mar 18 16:32:01 2015 -0500
+++ b/toys/posix/head.c	Thu Mar 19 13:57:02 2015 -0500
@@ -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 @@
 
 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);
 }