OSDN Git Service

release-request-60f1fc0d-1c6d-400a-8b4e-444f1452f036-for-git_oc-mr1-release-4157261...
authorandroid-build-team Robot <android-build-team-robot@google.com>
Thu, 6 Jul 2017 07:26:05 +0000 (07:26 +0000)
committerandroid-build-team Robot <android-build-team-robot@google.com>
Thu, 6 Jul 2017 07:26:05 +0000 (07:26 +0000)
Change-Id: I4f6769e7f2af3ee8cdf4b9c22354d9e2dca2bf6a

generated/flags.h
generated/globals.h
generated/help.h
generated/newtoys.h
lib/lib.c
main.c
tests/head.test
tests/strings.test [new file with mode: 0644]
toys/posix/head.c
toys/posix/strings.c
www/news.html

index a240db1..431b924 100644 (file)
 #undef FLAG_c
 #endif
 
-// head ?n#<0=10qv ?n#<0=10qv
+// head ?n#<0=10c#<0qv[-nc] ?n#<0=10c#<0qv[-nc]
 #undef OPTSTR_head
-#define OPTSTR_head "?n#<0=10qv"
+#define OPTSTR_head "?n#<0=10c#<0qv[-nc]"
 #ifdef CLEANUP_head
 #undef CLEANUP_head
 #undef FOR_head
 #undef FLAG_v
 #undef FLAG_q
+#undef FLAG_c
 #undef FLAG_n
 #endif
 
 #undef FOR_stop
 #endif
 
-// strings an#=4<1fo an#=4<1fo
+// strings t:an#=4<1fo t:an#=4<1fo
 #undef OPTSTR_strings
-#define OPTSTR_strings "an#=4<1fo"
+#define OPTSTR_strings "t:an#=4<1fo"
 #ifdef CLEANUP_strings
 #undef CLEANUP_strings
 #undef FOR_strings
 #undef FLAG_f
 #undef FLAG_n
 #undef FLAG_a
+#undef FLAG_t
 #endif
 
 // su   lmpc:s:
 #endif
 #define FLAG_v (1<<0)
 #define FLAG_q (1<<1)
-#define FLAG_n (1<<2)
+#define FLAG_c (1<<2)
+#define FLAG_n (1<<3)
 #endif
 
 #ifdef FOR_hello
 #define FLAG_f (1<<1)
 #define FLAG_n (1<<2)
 #define FLAG_a (1<<3)
+#define FLAG_t (1<<4)
 #endif
 
 #ifdef FOR_su
index 00fcc16..5e4f8ce 100644 (file)
@@ -1117,6 +1117,7 @@ struct grep_data {
 // toys/posix/head.c
 
 struct head_data {
+  long bytes;
   long lines;
   int file_no;
 };
@@ -1326,6 +1327,7 @@ struct split_data {
 
 struct strings_data {
   long num;
+  char *t;
 };
 
 // toys/posix/tail.c
index 49a14f9..811b534 100644 (file)
 
 #define HELP_tail "usage: tail [-n|c NUMBER] [-f] [FILE...]\n\nCopy last lines from files to stdout. If no files listed, copy from\nstdin. Filename \"-\" is a synonym for stdin.\n\n-n        output the last NUMBER lines (default 10), +X counts from start\n-c     output the last NUMBER bytes, +NUMBER counts from start\n-f     follow FILE(s), waiting for more data to be appended\n\n"
 
-#define HELP_strings "usage: strings [-fo] [-n LEN] [FILE...]\n\nDisplay printable strings in a binary file\n\n-f      Precede strings with filenames\n-n      At least LEN characters form a string (default 4)\n-o   Precede strings with decimal offsets\n\n"
+#define HELP_strings "usage: strings [-fo] [-t oxd] [-n LEN] [FILE...]\n\nDisplay printable strings in a binary file\n\n-f     Show filename\n-n       At least LEN characters form a string (default 4)\n-o   Show offset (ala -t d)\n-t      Show offset type (o=octal, d=decimal, x=hexadecimal)\n\n"
 
 #define HELP_split "usage: split [-a SUFFIX_LEN] [-b BYTES] [-l LINES] [INPUT [OUTPUT]]\n\nCopy INPUT (or stdin) data to a series of OUTPUT (or \"x\") files with\nalphabetically increasing suffix (aa, ab, ac... az, ba, bb...).\n\n-a       Suffix length (default 2)\n-b   BYTES/file (10, 10k, 10m, 10g...)\n-l   LINES/file (default 1000)\n\n"
 
 
 #define HELP_id "usage: id [-GZgnru] \n\nPrint user and group ID.\n-G  Show only the group IDs\n-Z     Show only security context\n-g  Show only the effective group ID\n-n    print names instead of numeric IDs (to be used with -Ggu)\n-r   Show real ID instead of effective ID\n-u        Show only the effective user ID\n"
 
-#define HELP_head "usage: head [-n number] [file...]\n\nCopy first lines from files to stdout. If no files listed, copy from\nstdin. Filename \"-\" is a synonym for stdin.\n\n-n      Number of lines to copy\n-q     Never print headers\n-v Always print headers\n\n"
+#define HELP_head "usage: head [-n number] [file...]\n\nCopy first lines from files to stdout. If no files listed, copy from\nstdin. Filename \"-\" is a synonym for stdin.\n\n-n      Number of lines to copy\n-c     Number of bytes to copy\n-q     Never print headers\n-v Always print headers\n\n"
 
 #define HELP_grep "usage: grep [-EFrivwcloqsHbhn] [-ABC NUM] [-m MAX] [-e REGEX]... [-MS PATTERN]... [-f REGFILE] [FILE]...\n\nShow lines matching regular expressions. If no -e, first argument is\nregular expression to match. With no files (or \"-\" filename) read stdin.\nReturns 0 if matched, 1 if no match found.\n\n-e  Regex to match. (May be repeated.)\n-f  File listing regular expressions to match.\n\nfile search:\n-r  Recurse into subdirectories (defaults FILE to \".\")\n-M  Match filename pattern (--include)\n-S  Skip filename pattern (--exclude)\n\nmatch type:\n-A  Show NUM lines after     -B  Show NUM lines before match\n-C  NUM lines context (A+B)  -E  extended regex syntax\n-F  fixed (literal match)    -i  case insensitive\n-m  match MAX many lines     -v  invert match\n-w  whole word (implies -E)  -x  whole line\n-z  input NUL terminated\n\ndisplay modes: (default: matched line)\n-c  count of matching lines  -l  show matching filenames\n-o  only matching part       -q  quiet (errors only)\n-s  silent (no error msg)    -Z  output NUL terminated\n\noutput prefix (default: filename if checking more than 1 file)\n-H  force filename           -b  byte offset of match\n-h  hide filename            -n  line number of match\n\n"
 
index fc2811d..3d62e0d 100644 (file)
@@ -89,7 +89,7 @@ USE_GROUPS(NEWTOY(groups, NULL, TOYFLAG_USR|TOYFLAG_BIN))
 USE_GUNZIP(NEWTOY(gunzip, "cdfk123456789", TOYFLAG_USR|TOYFLAG_BIN))
 USE_GZIP(NEWTOY(gzip,     "cdfk123456789", TOYFLAG_USR|TOYFLAG_BIN))
 USE_REBOOT(OLDTOY(halt, reboot, TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
-USE_HEAD(NEWTOY(head, "?n#<0=10qv", TOYFLAG_USR|TOYFLAG_BIN))
+USE_HEAD(NEWTOY(head, "?n#<0=10c#<0qv[-nc]", TOYFLAG_USR|TOYFLAG_BIN))
 USE_HELLO(NEWTOY(hello, 0, TOYFLAG_USR|TOYFLAG_BIN))
 USE_HELP(NEWTOY(help, ""USE_HELP_EXTRAS("ah"), TOYFLAG_BIN))
 USE_HEXEDIT(NEWTOY(hexedit, "<1>1r", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
@@ -217,7 +217,7 @@ USE_SPLIT(NEWTOY(split, ">2a#<1=2>9b#<1l#<1[!bl]", TOYFLAG_USR|TOYFLAG_BIN))
 USE_START(NEWTOY(start, "", TOYFLAG_USR|TOYFLAG_SBIN))
 USE_STAT(NEWTOY(stat, "<1c:fLt", TOYFLAG_BIN)) 
 USE_STOP(NEWTOY(stop, "", TOYFLAG_USR|TOYFLAG_SBIN))
-USE_STRINGS(NEWTOY(strings, "an#=4<1fo", TOYFLAG_USR|TOYFLAG_BIN))
+USE_STRINGS(NEWTOY(strings, "t:an#=4<1fo", TOYFLAG_USR|TOYFLAG_BIN))
 USE_SU(NEWTOY(su, "lmpc:s:", TOYFLAG_BIN|TOYFLAG_ROOTONLY))
 USE_SULOGIN(NEWTOY(sulogin, "t#<0=0", TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
 USE_SWAPOFF(NEWTOY(swapoff, "<1>1", TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
index ceb1bc7..6e88fd2 100644 (file)
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -299,11 +299,12 @@ long long atolx(char *numstr)
 
   val = xstrtol(numstr, &c, 0);
   if (c != numstr && *c && (end = strchr(suffixes, tolower(*c)))) {
-    int shift = end-suffixes-2;
+    int shift = end-suffixes-1;
 
-    if (shift >= 0) {
-      if (toupper(*++c)=='d') do val *= 1000; while (shift--);
-      else val *= 1024LL<<(shift*10);
+    if (!shift) val *= 512;
+    else if (shift>0) {
+      if (toupper(*++c)=='d') while (shift--) val *= 1000;
+      else val *= 1LL<<(shift*10);
     }
   }
   while (isspace(*c)) c++;
diff --git a/main.c b/main.c
index fcb8702..6025d43 100644 (file)
--- a/main.c
+++ b/main.c
@@ -6,7 +6,7 @@
 #include "toys.h"
 
 #ifndef TOYBOX_VERSION
-#define TOYBOX_VERSION "0.7.3"
+#define TOYBOX_VERSION "0.7.4"
 #endif
 
 // Populate toy_list[].
index 6ed027c..4e4c01b 100755 (executable)
@@ -27,3 +27,7 @@ testing "-q, multiple files" "head -q -n 2 input file1" "one\ntwo\nfoo\nbar\n" \
        "one\ntwo\nthree\n" ""
 rm file1
 
+testing "-c 3" "head -c 3" "one" "" "one\ntwo"
+testing "-c bigger than input" "head -c 3" "a" "" "a"
+testing "-c 3 -n 1" "head -c 3 -n 1" "one\n" "" "one\ntwo"
+testing "-n 1 -c 3" "head -n 1 -c 3" "one" "" "one\ntwo"
diff --git a/tests/strings.test b/tests/strings.test
new file mode 100644 (file)
index 0000000..8becc2f
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+[ -f testing.sh ] && . testing.sh
+
+#testing "name" "command" "result" "infile" "stdin"
+
+testing "stdin" "strings" "foobar\n" "" "foobar\n"
+testing "file" "strings input" "foobar\n" "foobar\n" ""
+testing "string to the end" "strings input" "foobar\n" "foobar" ""
+testing "short strings" "strings input" "" "foo\nbar\n" ""
+testing "-n6" "strings -n6 input" "foobar\n" "foobar\nbaz\n" ""
+testing "string and nulls" "strings input" "foobar\nbazfoo\n" \
+       "\0foobar\0\0bazfoo\0foo" ""
+testing "-f" "strings -f input" "input: foobar\n" "foobar\n" ""
+testing "-o" "strings -o input | sed 's/^ *//'" "6 foobar\n" \
+       "\0\0\0\0\0\0foobar\n" ""
+testing "-o, multiple strings" "strings -n3 -o input | sed 's/^ *//'" \
+       "1 foo\n7 bar\n" "\0foo\0b\0bar\n" ""
+testing "-fo" "strings -fo input | sed 's/: */: /'" "input: 6 foobar\n" \
+       "\0\0\0\0\0\0foobar\n" ""
index 63eb85b..ea4bbbc 100644 (file)
@@ -3,8 +3,10 @@
  * Copyright 2006 Timothy Elliott <tle@holymonkey.com>
  *
  * See http://opengroup.org/onlinepubs/9699919799/utilities/head.html
+ *
+ * Deviations from posix: -c
 
-USE_HEAD(NEWTOY(head, "?n#<0=10qv", TOYFLAG_USR|TOYFLAG_BIN))
+USE_HEAD(NEWTOY(head, "?n#<0=10c#<0qv[-nc]", TOYFLAG_USR|TOYFLAG_BIN))
 
 config HEAD
   bool "head"
@@ -16,6 +18,7 @@ config HEAD
     stdin. Filename "-" is a synonym for stdin.
 
     -n Number of lines to copy
+    -c Number of bytes to copy
     -q Never print headers
     -v Always print headers
 */
@@ -24,13 +27,14 @@ config HEAD
 #include "toys.h"
 
 GLOBALS(
+  long bytes;
   long lines;
   int file_no;
 )
 
 static void do_head(int fd, char *name)
 {
-  int i, len, lines=TT.lines, size=sizeof(toybuf);
+  int i, len, lines=TT.lines, bytes=TT.bytes;
 
   if ((toys.optc > 1 && !(toys.optflags & FLAG_q)) || toys.optflags & FLAG_v) {
     // Print an extra newline for all but the first file
@@ -39,12 +43,15 @@ static void do_head(int fd, char *name)
     xflush();
   }
 
-  while (lines) {
-    len = read(fd, toybuf, size);
+  while ((toys.optflags&FLAG_c) ? bytes : lines) {
+    len = read(fd, toybuf, sizeof(toybuf));
     if (len<0) perror_msg_raw(name);
     if (len<1) break;
 
-    for(i=0; i<len;) if (toybuf[i++] == '\n' && !--lines) break;
+    if (bytes) {
+      i = bytes >= len ? len : bytes;
+      bytes -= i;
+    } else for(i=0; i<len;) if (toybuf[i++] == '\n' && !--lines) break;
 
     xwrite(1, toybuf, i);
   }
index f3ce70c..911fc45 100644 (file)
@@ -3,23 +3,29 @@
  * Copyright 2014 Kyung-su Kim <kaspyx@gmail.com>
  * Copyright 2014 Kyungwan Han <asura321@gmail.com>
  *
- * No Standard
+ * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/strings.html
+ *
+ * Deviations from posix: we don't readahead to the end of the string to see
+ * if it ends with NUL or newline before printing. Add -o. We always do -a
+ * (and accept but don't document the flag), but that's sort of conformant.
+ * Posix' STDOUT section says things like "%o %s" and we support 64 bit offsets.
+ *
  * TODO: utf8 strings
- * TODO: posix -t
 
-USE_STRINGS(NEWTOY(strings, "an#=4<1fo", TOYFLAG_USR|TOYFLAG_BIN))
+USE_STRINGS(NEWTOY(strings, "t:an#=4<1fo", TOYFLAG_USR|TOYFLAG_BIN))
 
 config STRINGS
   bool "strings"
   default y
   help
-    usage: strings [-fo] [-n LEN] [FILE...]
+    usage: strings [-fo] [-t oxd] [-n LEN] [FILE...]
 
     Display printable strings in a binary file
 
-    -f Precede strings with filenames
+    -f Show filename
     -n At least LEN characters form a string (default 4)
-    -o Precede strings with decimal offsets
+    -o Show offset (ala -t d)
+    -t Show offset type (o=octal, d=decimal, x=hexadecimal)
 */
 
 #define FOR_strings
@@ -27,35 +33,51 @@ config STRINGS
 
 GLOBALS(
   long num;
+  char *t;
 )
 
 static void do_strings(int fd, char *filename)
 {
   int nread, i, wlen = TT.num, count = 0;
   off_t offset = 0;
-  char *string = xzalloc(wlen + 1);
+  char *string = 0, pattern[8];
+
+  if (TT.t) if (!(string = strchr("oxd", *TT.t))) error_exit("-t needs oxd");
+  sprintf(pattern, "%%7ll%c ", string ? *string : 'd');
+
+  // input buffer can wrap before we have enough data to output, so
+  // copy start of string to temporary buffer until enough to output
+  string = xzalloc(wlen+1);
+
+  for (i = nread = 0; ;i++) {
+    if (i >= nread) {
+      nread = read(fd, toybuf, sizeof(toybuf));
+      i = 0;
+      if (nread < 0) perror_msg_raw(filename);
+      if (nread < 1) {
+        if (count) goto flush;
+        break;
+      }
+    }
 
-  for (;;) {
-    nread = read(fd, toybuf, sizeof(toybuf));
-    if (nread < 0) perror_msg_raw(filename);
-    if (nread < 1) break;
-    for (i = 0; i < nread; i++, offset++) {
-      if (((toybuf[i] >= 32) && (toybuf[i] <= 126)) || (toybuf[i] == '\t')) {
-        if (count == wlen) fputc(toybuf[i], stdout);
-        else {
-          string[count++] = toybuf[i];
-          if (count == wlen) {
-            if (toys.optflags & FLAG_f) printf("%s: ", filename);
-            if (toys.optflags & FLAG_o)
-              printf("%7lld ",(long long)(offset - wlen));
-            printf("%s", string);
-          }
+    offset++;
+    if ((toybuf[i]>=32 && toybuf[i]<=126) || toybuf[i]=='\t') {
+      if (count == wlen) fputc(toybuf[i], stdout);
+      else {
+        string[count++] = toybuf[i];
+        if (count == wlen) {
+          if (toys.optflags & FLAG_f) printf("%s: ", filename);
+          if (toys.optflags & (FLAG_o|FLAG_t))
+            printf(pattern, (long long)(offset - wlen));
+          printf("%s", string);
         }
-      } else {
-        if (count == wlen) xputc('\n');
-        count = 0;
       }
+      continue;
     }
+flush:
+    // End of previous string
+    if (count == wlen) xputc('\n');
+    count = 0;
   }
   xclose(fd);
   free(string);
index 73516b0..f2733a7 100755 (executable)
@@ -8,6 +8,93 @@ a development environment. See the links on the left for details.</p>
 
 <h2>News</h2>
 
+<a name="19-06-2017" /><a href="#19-06-2017"><hr><h2><b>June 19, 2017</b></h2></a>
+<blockquote><p>It is a well-known fact that those people who most want to rule people are, ipso facto, those least suited to do it.
+To summarize the summary: anyone who is capable of getting themselves made President should on no account be allowed to do the job.</p>
+<p>- The Hitchhiker's Guide to the Galaxy</p>
+</blockquote>
+
+<p><a href=downloads/toybox-0.7.4.tar.gz>Toybox 0.7.4</a>
+(<a href=https://github.com/landley/toybox/releases/tag/0.7.4>git commit</a>)
+is out. No new commands this time, but
+<b>chrt</b> and <b>dmesg</b> got promoted out of pending.</p>
+
+<p><u>New features</u>:
+Rob rewrote paste, which should work much better now, and added grep
+-M and -S to match and skip wildcards respectively (useful with -r).
+Elliott's updated dmesg has -T and --color. The file
+command can recognize gzip now, uptime grew -s, date grew %N, env knows - as a first argument
+means -i (posix!) and grew -0, ls defaults to -b
+instead of -q now when there's a tty, and ls has a new -ll option (with
+--full-time as a compatibility synonym) showing nanoseconds and (for some
+reason) timezone. (Why do individual files have timezones?) Elliott added
+"uudecode -o -" support. Illya Kuzmich taught head -v and -q. The cpio
+code no longer adds the "TRAILER!!!" entry by default (initramfs extractor
+doesn't care) without which you can concatenate cpio archives with "cat".
+(Use the new --trailer option if you want the legacy behavior.)
+In pending, fdisk compiles now and tar understands bzip2.</p>
+
+<p><u>Build</u>:
+The "make install_airlock" target now symlinks bc from the host because
+the kernel <a href=https://landley.net/notes-2013.html#28-03-2013>inexplicably</a>
+needs that to build. This was motivated by
+<a href=https://github.com/landley/mkroot>mkroot</a>, which builds under
+a toybox airlock directory.</p>
+
+<p>Lots of work on the test suite, mostly from the Android guys who are now
+running it under Android. This fixed several existing tests that didn't
+pass, made more tests run on a toybox-only system, and so on. The test suite
+infrastructure now has a second testing function,
+"testcmd", which supplies the command name being tested (bypassing
+shell builtins).</p>
+
+<p>Various android build and config fixes, getting closer to being able
+to let android someday use scripts/make.sh instead of generated/* snapshots.
+Also more work into building under android's NDK; not quite there yet
+but much closer.
+Use nproc in scripts/make.sh detect available processors (so you can control the SMP level with taskset).
+Removed the old uClibc compatibility glue, it's been 5 years since their
+<a href=http://lists.busybox.net/pipermail/buildroot/2016-December/180102.html>last release</a>.</p>
+
+<p>The new config option TOYBOX_PEDANTIC_ARGS checks arguments when there
+are no arguments, so things like "uptime" no longer silently ignore arguments
+you pass but instead refuse to run.</p>
+
+<p><u>Docs</u>:
+The FAQ now has more than one entry. Commands no longer output the full
+help text for argument errors but instead just say "See %s --help" with the
+command name (in addition to the actual error message).
+Elliott did a big period-ectomy on all the --help text, and
+we cleaned up some tab/space inconsistency. The
+non-html help -a output now has separators with the command name.
+The top/iotop and pkill/pgrep help text now describe a lot more of what
+the commands can do. Twitter's code of conduct page went down so we
+mirrored the text locally.</p>
+
+<p><u>Bugfixes</u>:
+Fixed a race condition in ps/top where a process that exited right as we
+read its data returned a different error value than we were expecting (which
+was causing long-running top instances to occasionally exit),
+mount now gives an error if it can't autodetect the filesystem
+type, ps no longer queries the terminal size when output isn't to a tty
+(so "ps -A | cat" doesn't vary), date's chkmktime() was replaced with
+simple range checks for fields (to avoid false positives from things like
+timezones and daylight savings time), removed %s from date's help (we
+didn't implement it, we have @seconds[.nanoseconds] instead), fixed
+zcat's buffer flush logic (which was always failing on files larger
+than 32k), and factor now detects requests for numbers >64 bits and fails
+loudly instead of producing incorrect answers.
+Elliott fixed touch -a/-m (they were backwards), and allowed ':' in
+setprop's property names. Grep now exits with 2 for errors (so -q can
+distinguish "didn't find" from "didn't work"), doesn't stop on symlinks
+that point nowhere (there was an error_exit() that should just be a warning),
+and provides error messages for files we could open but not read.</p>
+
+<p><u>Library</u>:
+New library functions: strend() complements strstart(), minof()/maxof()
+are min/max macros that evalute arguments once and autodetect type (why
+isn't this in libc?), xmmap() checks MAP_FAILED (which is not NULL).</p>
+
 <a name="21-02-2017" /><a href="#21-02-2017"><hr><h2><b>February 21, 2017</b></h2></a>
 <blockquote><p>Only six people in the Galaxy knew that the job of the
 Galactic President was not to wield power but to attract attention