OSDN Git Service

merge in oc-release history after reset to master
[android-x86/external-toybox.git] / toys / posix / head.c
index ba7b738..f300760 100644 (file)
@@ -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_USR|TOYFLAG_BIN))
 
 config HEAD
   bool "head"
@@ -39,10 +39,7 @@ static void do_head(int fd, char *name)
 
   while (lines) {
     len = read(fd, toybuf, size);
-    if (len<0) {
-      perror_msg("%s",name);
-      toys.exitval = EXIT_FAILURE;
-    }
+    if (len<0) perror_msg_raw(name);
     if (len<1) break;
 
     for(i=0; i<len;) if (toybuf[i++] == '\n' && !--lines) break;
@@ -53,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--;
+  } else arg = 0;
+  loopfiles(toys.optargs+!!arg, do_head);
 }