[Toybox] [PATCH] tail -X

enh enh at google.com
Mon Mar 16 21:37:02 PDT 2015


Allow "tail -X" as well as "tail -n X".

diff --git a/toys/posix/tail.c b/toys/posix/tail.c
index e92c044..3604582 100644
--- a/toys/posix/tail.c
+++ b/toys/posix/tail.c
@@ -4,7 +4,7 @@
  *
  * See http://opengroup.org/onlinepubs/9699919799/utilities/tail.html

-USE_TAIL(NEWTOY(tail, "fc-n-[-cn]", TOYFLAG_BIN))
+USE_TAIL(NEWTOY(tail, "?fc-n-[-cn]", TOYFLAG_BIN))

 config TAIL
   bool "tail"
@@ -213,10 +213,14 @@ static void do_tail(int fd, char *name)

 void tail_main(void)
 {
-  // if nothing specified, default -n to -10
-  if (!(toys.optflags&(FLAG_n|FLAG_c))) TT.lines = -10;
+  char **args = toys.optargs;

-  loopfiles(toys.optargs, do_tail);
+  if (*args && **args == '-') {
+    TT.lines = xstrtol(*(args++), NULL, 10);
+    toys.optc--;
+  } else if (!(toys.optflags&(FLAG_n|FLAG_c))) TT.lines = -10;
+
+  loopfiles(args, do_tail);

   // do -f stuff
 }

 1426567022.0


More information about the Toybox mailing list