aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2021-10-07 23:50:17 +0000
committerElliott Hughes <enh@google.com>2021-10-07 17:27:35 -0700
commite0ccc47a57fca4a98de18dc778eb66cf02cdf02a (patch)
tree5ac897d500491a81da2cc644c36dbf0e7336acb0
parentc135e01052c08a73034572908209ef08c5025f26 (diff)
downloadtoybox-android-s-v2-preview-1.tar.gz
Reland "Upgrade toybox to 1986075975db4cdab08133f8299ad72dd5af4b23".android-s-v2-preview-2android-s-v2-preview-1android-s-v2-beta-2android-s-v2-preview-1
This reverts commit c135e01052c08a73034572908209ef08c5025f26, but adds the now-necessary `-Wl,-dead_strip` to the Darwin linker flags. Test: treehugger Change-Id: Ie75d29692c4aaf51d84a2ba148d62cbc176c8610
-rw-r--r--.config-device2
-rw-r--r--.config-linux2
-rw-r--r--.config-mac2
-rw-r--r--Android.bp3
-rw-r--r--METADATA6
-rw-r--r--android/device/generated/config.h4
-rw-r--r--android/device/generated/flags.h36
-rw-r--r--android/device/generated/globals.h16
-rw-r--r--android/device/generated/help.h6
-rw-r--r--android/device/generated/newtoys.h4
-rw-r--r--android/linux/generated/config.h4
-rw-r--r--android/linux/generated/flags.h36
-rw-r--r--android/linux/generated/globals.h16
-rw-r--r--android/linux/generated/help.h6
-rw-r--r--android/linux/generated/newtoys.h4
-rw-r--r--android/mac/generated/config.h4
-rw-r--r--android/mac/generated/flags.h36
-rw-r--r--android/mac/generated/globals.h16
-rw-r--r--android/mac/generated/help.h6
-rw-r--r--android/mac/generated/newtoys.h4
-rwxr-xr-xconfigure4
-rw-r--r--lib/lib.c3
-rw-r--r--lib/portability.h2
-rwxr-xr-xtests/hexdump.test135
-rw-r--r--toys/lsb/pidof.c12
-rw-r--r--toys/pending/hexdump.c155
26 files changed, 497 insertions, 27 deletions
diff --git a/.config-device b/.config-device
index 888db93b..dd7b2efd 100644
--- a/.config-device
+++ b/.config-device
@@ -144,7 +144,9 @@ CONFIG_HEAD=y
# CONFIG_HELLO is not set
CONFIG_HELP_EXTRAS=y
CONFIG_HELP=y
+# CONFIG_HEXDUMP is not set
# CONFIG_HEXEDIT is not set
+# CONFIG_HD is not set
# CONFIG_HOSTID is not set
# CONFIG_HOST is not set
CONFIG_HOSTNAME=y
diff --git a/.config-linux b/.config-linux
index 493cee1c..3b1c23f3 100644
--- a/.config-linux
+++ b/.config-linux
@@ -142,7 +142,9 @@ CONFIG_HEAD=y
# CONFIG_HELLO is not set
# CONFIG_HELP_EXTRAS is not set
# CONFIG_HELP is not set
+# CONFIG_HEXDUMP is not set
# CONFIG_HEXEDIT is not set
+# CONFIG_HD is not set
# CONFIG_HOSTID is not set
# CONFIG_HOST is not set
CONFIG_HOSTNAME=y
diff --git a/.config-mac b/.config-mac
index 30cdb16d..8947f281 100644
--- a/.config-mac
+++ b/.config-mac
@@ -142,7 +142,9 @@ CONFIG_HEAD=y
# CONFIG_HELLO is not set
# CONFIG_HELP_EXTRAS is not set
# CONFIG_HELP is not set
+# CONFIG_HEXDUMP is not set
# CONFIG_HEXEDIT is not set
+# CONFIG_HD is not set
# CONFIG_HOSTID is not set
# CONFIG_HOST is not set
CONFIG_HOSTNAME=y
diff --git a/Android.bp b/Android.bp
index 4e5f3976..a4987c7c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -462,6 +462,9 @@ cc_defaults {
// also getting from <sys/param.h>.
"-Wno-macro-redefined",
],
+ ldflags: [
+ "-Wl,-dead_strip",
+ ],
},
linux: {
diff --git a/METADATA b/METADATA
index de06cbec..5aa1a363 100644
--- a/METADATA
+++ b/METADATA
@@ -9,11 +9,11 @@ third_party {
type: GIT
value: "https://github.com/landley/toybox"
}
- version: "340b1cf8f79cc9ea7232453e0052d2418c806103"
+ version: "1986075975db4cdab08133f8299ad72dd5af4b23"
license_type: UNENCUMBERED
last_upgrade_date {
year: 2021
- month: 9
- day: 30
+ month: 10
+ day: 6
}
}
diff --git a/android/device/generated/config.h b/android/device/generated/config.h
index 7558a5ba..fa21fed2 100644
--- a/android/device/generated/config.h
+++ b/android/device/generated/config.h
@@ -262,8 +262,12 @@
#define USE_HELP_EXTRAS(...) __VA_ARGS__
#define CFG_HELP 1
#define USE_HELP(...) __VA_ARGS__
+#define CFG_HEXDUMP 0
+#define USE_HEXDUMP(...)
#define CFG_HEXEDIT 0
#define USE_HEXEDIT(...)
+#define CFG_HD 0
+#define USE_HD(...)
#define CFG_HOSTID 0
#define USE_HOSTID(...)
#define CFG_HOST 0
diff --git a/android/device/generated/flags.h b/android/device/generated/flags.h
index 641112e7..809a29b2 100644
--- a/android/device/generated/flags.h
+++ b/android/device/generated/flags.h
@@ -1267,6 +1267,23 @@
#undef FLAG_a
#endif
+// hexdump bcCdn#<0os#<0vx[!bcCdox]
+#undef OPTSTR_hexdump
+#define OPTSTR_hexdump "bcCdn#<0os#<0vx[!bcCdox]"
+#ifdef CLEANUP_hexdump
+#undef CLEANUP_hexdump
+#undef FOR_hexdump
+#undef FLAG_x
+#undef FLAG_v
+#undef FLAG_s
+#undef FLAG_o
+#undef FLAG_n
+#undef FLAG_d
+#undef FLAG_C
+#undef FLAG_c
+#undef FLAG_b
+#endif
+
// hexedit <1>1r
#undef OPTSTR_hexedit
#define OPTSTR_hexedit "<1>1r"
@@ -2256,9 +2273,9 @@
#undef FLAG_c
#endif
-// pidof <1so:x <1so:x
+// pidof so:x so:x
#undef OPTSTR_pidof
-#define OPTSTR_pidof "<1so:x"
+#define OPTSTR_pidof "so:x"
#ifdef CLEANUP_pidof
#undef CLEANUP_pidof
#undef FOR_pidof
@@ -4709,6 +4726,21 @@
#define FLAG_a (1<<2)
#endif
+#ifdef FOR_hexdump
+#ifndef TT
+#define TT this.hexdump
+#endif
+#define FLAG_x (FORCED_FLAG<<0)
+#define FLAG_v (FORCED_FLAG<<1)
+#define FLAG_s (FORCED_FLAG<<2)
+#define FLAG_o (FORCED_FLAG<<3)
+#define FLAG_n (FORCED_FLAG<<4)
+#define FLAG_d (FORCED_FLAG<<5)
+#define FLAG_C (FORCED_FLAG<<6)
+#define FLAG_c (FORCED_FLAG<<7)
+#define FLAG_b (FORCED_FLAG<<8)
+#endif
+
#ifdef FOR_hexedit
#ifndef TT
#define TT this.hexedit
diff --git a/android/device/generated/globals.h b/android/device/generated/globals.h
index 1eede5a7..cb866143 100644
--- a/android/device/generated/globals.h
+++ b/android/device/generated/globals.h
@@ -117,7 +117,7 @@ struct passwd_data {
// toys/lsb/pidof.c
struct pidof_data {
- char *omit;
+ char *o;
};
// toys/lsb/seq.c
@@ -722,6 +722,19 @@ struct groupadd_data {
long gid;
};
+// toys/pending/hexdump.c
+
+struct hexdump_data {
+ long s, n;
+
+ long long len, pos, ppos;
+ const char *fmt;
+ unsigned int fn, bc; // file number and byte count
+ char linebuf[16]; // line buffer - serves double duty for sqeezing repeat
+ // lines and for accumulating full lines accross file
+ // boundaries if necessesary.
+};
+
// toys/pending/host.c
struct host_data {
@@ -1676,6 +1689,7 @@ extern union global_union {
struct getopt_data getopt;
struct getty_data getty;
struct groupadd_data groupadd;
+ struct hexdump_data hexdump;
struct host_data host;
struct ip_data ip;
struct ipcrm_data ipcrm;
diff --git a/android/device/generated/help.h b/android/device/generated/help.h
index 9a533c68..52624b88 100644
--- a/android/device/generated/help.h
+++ b/android/device/generated/help.h
@@ -72,7 +72,7 @@
#define HELP_seq "usage: seq [-w|-f fmt_str] [-s sep_str] [first] [increment] last\n\nCount from first to last, by increment. Omitted arguments default\nto 1. Two arguments are used as first and last. Arguments can be\nnegative or floating point.\n\n-f Use fmt_str as a printf-style floating point format string\n-s Use sep_str as separator, default is a newline character\n-w Pad to equal width with leading zeroes"
-#define HELP_pidof "usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME]...\n\nPrint the PIDs of all processes with the given names.\n\n-s Single shot, only return one pid\n-o Omit PID(s)\n-x Match shell scripts too"
+#define HELP_pidof "usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME...]\n\nPrint the PIDs of all processes with the given names.\n\n-o Omit PID(s)\n-s Single shot, only return one pid\n-x Match shell scripts too"
#define HELP_passwd_sad "Password changes are checked to make sure they're at least 6 chars long,\ndon't include the entire username (but not a subset of it), or the entire\nprevious password (but changing password1, password2, password3 is fine).\nThis heuristic accepts \"aaaaaa\" and \"123456\"."
@@ -430,6 +430,10 @@
#define HELP_host "usage: host [-av] [-t TYPE] NAME [SERVER]\n\nPerform DNS lookup on NAME, which can be a domain name to lookup,\nor an IPv4 dotted or IPv6 colon-separated address to reverse lookup.\nSERVER (if present) is the DNS server to use.\n\n-a -v -t ANY\n-t TYPE query records of type TYPE\n-v verbose"
+#define HELP_hd "usage: hd [FILE...]\n\nDisplay file(s) in cannonical hex+ASCII format."
+
+#define HELP_hexdump "usage: hexdump [-bcCdovx] [-n LEN] [-s SKIP] [FILE...]\n\nDump file(s) in hexadecimal format.\n\n-n LEN Show LEN bytes of output\n-s SKIP Skip bytes of input\n-v Verbose (don't combine identical lines)\n\nDisplay type:\n-b One byte octal -c One byte character -C Canonical (hex + ASCII)\n-d Two byte decimal -o Two byte octal -x Two byte hexadecimal (default)"
+
#define HELP_groupdel "usage: groupdel [USER] GROUP\n\nDelete a group or remove a user from a group"
#define HELP_groupadd "usage: groupadd [-S] [-g GID] [USER] GROUP\n\nAdd a group or add a user to a group\n\n -g GID Group id\n -S Create a system group"
diff --git a/android/device/generated/newtoys.h b/android/device/generated/newtoys.h
index ecbabab5..81d4725a 100644
--- a/android/device/generated/newtoys.h
+++ b/android/device/generated/newtoys.h
@@ -109,9 +109,11 @@ USE_GROUPS(NEWTOY(groups, NULL, TOYFLAG_USR|TOYFLAG_BIN))
USE_GUNZIP(NEWTOY(gunzip, "cdfk123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN))
USE_GZIP(NEWTOY(gzip, "ncdfk123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN))
USE_REBOOT(OLDTOY(halt, reboot, TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
+USE_HD(OLDTOY(hd, hexdump, TOYFLAG_USR|TOYFLAG_BIN))
USE_HEAD(NEWTOY(head, "?n(lines)#<0=10c(bytes)#<0qv[-nc]", TOYFLAG_USR|TOYFLAG_BIN))
USE_HELLO(NEWTOY(hello, 0, TOYFLAG_USR|TOYFLAG_BIN))
USE_HELP(NEWTOY(help, "ahu", TOYFLAG_BIN|TOYFLAG_MAYFORK))
+USE_HEXDUMP(NEWTOY(hexdump, "bcCdn#<0os#<0vx[!bcCdox]", TOYFLAG_USR|TOYFLAG_BIN))
USE_HEXEDIT(NEWTOY(hexedit, "<1>1r", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
USE_HOST(NEWTOY(host, "<1>2avt:", TOYFLAG_USR|TOYFLAG_BIN))
USE_HOSTID(NEWTOY(hostid, ">0", TOYFLAG_USR|TOYFLAG_BIN))
@@ -199,7 +201,7 @@ USE_PASSWD(NEWTOY(passwd, ">1a:dlu", TOYFLAG_STAYROOT|TOYFLAG_USR|TOYFLAG_BIN))
USE_PASTE(NEWTOY(paste, "d:s", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
USE_PATCH(NEWTOY(patch, ">2(no-backup-if-mismatch)(dry-run)"USE_TOYBOX_DEBUG("x")"F#g#fulp#d:i:Rs(quiet)", TOYFLAG_USR|TOYFLAG_BIN))
USE_PGREP(NEWTOY(pgrep, "?cld:u*U*t*s*P*g*G*fnovxL:[-no]", TOYFLAG_USR|TOYFLAG_BIN))
-USE_PIDOF(NEWTOY(pidof, "<1so:x", TOYFLAG_BIN))
+USE_PIDOF(NEWTOY(pidof, "so:x", TOYFLAG_BIN))
USE_PING(NEWTOY(ping, "<1>1m#t#<0>255=64c#<0=3s#<0>4064=56i%W#<0=3w#<0qf46I:[-46]", TOYFLAG_USR|TOYFLAG_BIN))
USE_PING(OLDTOY(ping6, ping, TOYFLAG_USR|TOYFLAG_BIN))
USE_PIVOT_ROOT(NEWTOY(pivot_root, "<2>2", TOYFLAG_SBIN))
diff --git a/android/linux/generated/config.h b/android/linux/generated/config.h
index de38960f..82814f97 100644
--- a/android/linux/generated/config.h
+++ b/android/linux/generated/config.h
@@ -258,8 +258,12 @@
#define USE_HELP_EXTRAS(...)
#define CFG_HELP 0
#define USE_HELP(...)
+#define CFG_HEXDUMP 0
+#define USE_HEXDUMP(...)
#define CFG_HEXEDIT 0
#define USE_HEXEDIT(...)
+#define CFG_HD 0
+#define USE_HD(...)
#define CFG_HOSTID 0
#define USE_HOSTID(...)
#define CFG_HOST 0
diff --git a/android/linux/generated/flags.h b/android/linux/generated/flags.h
index c315a28a..78a35cb0 100644
--- a/android/linux/generated/flags.h
+++ b/android/linux/generated/flags.h
@@ -1267,6 +1267,23 @@
#undef FLAG_a
#endif
+// hexdump bcCdn#<0os#<0vx[!bcCdox]
+#undef OPTSTR_hexdump
+#define OPTSTR_hexdump "bcCdn#<0os#<0vx[!bcCdox]"
+#ifdef CLEANUP_hexdump
+#undef CLEANUP_hexdump
+#undef FOR_hexdump
+#undef FLAG_x
+#undef FLAG_v
+#undef FLAG_s
+#undef FLAG_o
+#undef FLAG_n
+#undef FLAG_d
+#undef FLAG_C
+#undef FLAG_c
+#undef FLAG_b
+#endif
+
// hexedit <1>1r
#undef OPTSTR_hexedit
#define OPTSTR_hexedit "<1>1r"
@@ -2256,9 +2273,9 @@
#undef FLAG_c
#endif
-// pidof <1so:x
+// pidof so:x
#undef OPTSTR_pidof
-#define OPTSTR_pidof "<1so:x"
+#define OPTSTR_pidof "so:x"
#ifdef CLEANUP_pidof
#undef CLEANUP_pidof
#undef FOR_pidof
@@ -4709,6 +4726,21 @@
#define FLAG_a (FORCED_FLAG<<2)
#endif
+#ifdef FOR_hexdump
+#ifndef TT
+#define TT this.hexdump
+#endif
+#define FLAG_x (FORCED_FLAG<<0)
+#define FLAG_v (FORCED_FLAG<<1)
+#define FLAG_s (FORCED_FLAG<<2)
+#define FLAG_o (FORCED_FLAG<<3)
+#define FLAG_n (FORCED_FLAG<<4)
+#define FLAG_d (FORCED_FLAG<<5)
+#define FLAG_C (FORCED_FLAG<<6)
+#define FLAG_c (FORCED_FLAG<<7)
+#define FLAG_b (FORCED_FLAG<<8)
+#endif
+
#ifdef FOR_hexedit
#ifndef TT
#define TT this.hexedit
diff --git a/android/linux/generated/globals.h b/android/linux/generated/globals.h
index 1eede5a7..cb866143 100644
--- a/android/linux/generated/globals.h
+++ b/android/linux/generated/globals.h
@@ -117,7 +117,7 @@ struct passwd_data {
// toys/lsb/pidof.c
struct pidof_data {
- char *omit;
+ char *o;
};
// toys/lsb/seq.c
@@ -722,6 +722,19 @@ struct groupadd_data {
long gid;
};
+// toys/pending/hexdump.c
+
+struct hexdump_data {
+ long s, n;
+
+ long long len, pos, ppos;
+ const char *fmt;
+ unsigned int fn, bc; // file number and byte count
+ char linebuf[16]; // line buffer - serves double duty for sqeezing repeat
+ // lines and for accumulating full lines accross file
+ // boundaries if necessesary.
+};
+
// toys/pending/host.c
struct host_data {
@@ -1676,6 +1689,7 @@ extern union global_union {
struct getopt_data getopt;
struct getty_data getty;
struct groupadd_data groupadd;
+ struct hexdump_data hexdump;
struct host_data host;
struct ip_data ip;
struct ipcrm_data ipcrm;
diff --git a/android/linux/generated/help.h b/android/linux/generated/help.h
index 8a9f3aa6..cd0919a2 100644
--- a/android/linux/generated/help.h
+++ b/android/linux/generated/help.h
@@ -72,7 +72,7 @@
#define HELP_seq "usage: seq [-w|-f fmt_str] [-s sep_str] [first] [increment] last\n\nCount from first to last, by increment. Omitted arguments default\nto 1. Two arguments are used as first and last. Arguments can be\nnegative or floating point.\n\n-f Use fmt_str as a printf-style floating point format string\n-s Use sep_str as separator, default is a newline character\n-w Pad to equal width with leading zeroes"
-#define HELP_pidof "usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME]...\n\nPrint the PIDs of all processes with the given names.\n\n-s Single shot, only return one pid\n-o Omit PID(s)\n-x Match shell scripts too"
+#define HELP_pidof "usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME...]\n\nPrint the PIDs of all processes with the given names.\n\n-o Omit PID(s)\n-s Single shot, only return one pid\n-x Match shell scripts too"
#define HELP_passwd_sad "Password changes are checked to make sure they're at least 6 chars long,\ndon't include the entire username (but not a subset of it), or the entire\nprevious password (but changing password1, password2, password3 is fine).\nThis heuristic accepts \"aaaaaa\" and \"123456\"."
@@ -432,6 +432,10 @@
#define HELP_host "usage: host [-av] [-t TYPE] NAME [SERVER]\n\nPerform DNS lookup on NAME, which can be a domain name to lookup,\nor an IPv4 dotted or IPv6 colon-separated address to reverse lookup.\nSERVER (if present) is the DNS server to use.\n\n-a -v -t ANY\n-t TYPE query records of type TYPE\n-v verbose"
+#define HELP_hd "usage: hd [FILE...]\n\nDisplay file(s) in cannonical hex+ASCII format."
+
+#define HELP_hexdump "usage: hexdump [-bcCdovx] [-n LEN] [-s SKIP] [FILE...]\n\nDump file(s) in hexadecimal format.\n\n-n LEN Show LEN bytes of output\n-s SKIP Skip bytes of input\n-v Verbose (don't combine identical lines)\n\nDisplay type:\n-b One byte octal -c One byte character -C Canonical (hex + ASCII)\n-d Two byte decimal -o Two byte octal -x Two byte hexadecimal (default)"
+
#define HELP_groupdel "usage: groupdel [USER] GROUP\n\nDelete a group or remove a user from a group"
#define HELP_groupadd "usage: groupadd [-S] [-g GID] [USER] GROUP\n\nAdd a group or add a user to a group\n\n -g GID Group id\n -S Create a system group"
diff --git a/android/linux/generated/newtoys.h b/android/linux/generated/newtoys.h
index ecbabab5..81d4725a 100644
--- a/android/linux/generated/newtoys.h
+++ b/android/linux/generated/newtoys.h
@@ -109,9 +109,11 @@ USE_GROUPS(NEWTOY(groups, NULL, TOYFLAG_USR|TOYFLAG_BIN))
USE_GUNZIP(NEWTOY(gunzip, "cdfk123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN))
USE_GZIP(NEWTOY(gzip, "ncdfk123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN))
USE_REBOOT(OLDTOY(halt, reboot, TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
+USE_HD(OLDTOY(hd, hexdump, TOYFLAG_USR|TOYFLAG_BIN))
USE_HEAD(NEWTOY(head, "?n(lines)#<0=10c(bytes)#<0qv[-nc]", TOYFLAG_USR|TOYFLAG_BIN))
USE_HELLO(NEWTOY(hello, 0, TOYFLAG_USR|TOYFLAG_BIN))
USE_HELP(NEWTOY(help, "ahu", TOYFLAG_BIN|TOYFLAG_MAYFORK))
+USE_HEXDUMP(NEWTOY(hexdump, "bcCdn#<0os#<0vx[!bcCdox]", TOYFLAG_USR|TOYFLAG_BIN))
USE_HEXEDIT(NEWTOY(hexedit, "<1>1r", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
USE_HOST(NEWTOY(host, "<1>2avt:", TOYFLAG_USR|TOYFLAG_BIN))
USE_HOSTID(NEWTOY(hostid, ">0", TOYFLAG_USR|TOYFLAG_BIN))
@@ -199,7 +201,7 @@ USE_PASSWD(NEWTOY(passwd, ">1a:dlu", TOYFLAG_STAYROOT|TOYFLAG_USR|TOYFLAG_BIN))
USE_PASTE(NEWTOY(paste, "d:s", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
USE_PATCH(NEWTOY(patch, ">2(no-backup-if-mismatch)(dry-run)"USE_TOYBOX_DEBUG("x")"F#g#fulp#d:i:Rs(quiet)", TOYFLAG_USR|TOYFLAG_BIN))
USE_PGREP(NEWTOY(pgrep, "?cld:u*U*t*s*P*g*G*fnovxL:[-no]", TOYFLAG_USR|TOYFLAG_BIN))
-USE_PIDOF(NEWTOY(pidof, "<1so:x", TOYFLAG_BIN))
+USE_PIDOF(NEWTOY(pidof, "so:x", TOYFLAG_BIN))
USE_PING(NEWTOY(ping, "<1>1m#t#<0>255=64c#<0=3s#<0>4064=56i%W#<0=3w#<0qf46I:[-46]", TOYFLAG_USR|TOYFLAG_BIN))
USE_PING(OLDTOY(ping6, ping, TOYFLAG_USR|TOYFLAG_BIN))
USE_PIVOT_ROOT(NEWTOY(pivot_root, "<2>2", TOYFLAG_SBIN))
diff --git a/android/mac/generated/config.h b/android/mac/generated/config.h
index 108ea0a8..48f344f4 100644
--- a/android/mac/generated/config.h
+++ b/android/mac/generated/config.h
@@ -258,8 +258,12 @@
#define USE_HELP_EXTRAS(...)
#define CFG_HELP 0
#define USE_HELP(...)
+#define CFG_HEXDUMP 0
+#define USE_HEXDUMP(...)
#define CFG_HEXEDIT 0
#define USE_HEXEDIT(...)
+#define CFG_HD 0
+#define USE_HD(...)
#define CFG_HOSTID 0
#define USE_HOSTID(...)
#define CFG_HOST 0
diff --git a/android/mac/generated/flags.h b/android/mac/generated/flags.h
index 568b3b49..dae3f5ec 100644
--- a/android/mac/generated/flags.h
+++ b/android/mac/generated/flags.h
@@ -1267,6 +1267,23 @@
#undef FLAG_a
#endif
+// hexdump bcCdn#<0os#<0vx[!bcCdox]
+#undef OPTSTR_hexdump
+#define OPTSTR_hexdump "bcCdn#<0os#<0vx[!bcCdox]"
+#ifdef CLEANUP_hexdump
+#undef CLEANUP_hexdump
+#undef FOR_hexdump
+#undef FLAG_x
+#undef FLAG_v
+#undef FLAG_s
+#undef FLAG_o
+#undef FLAG_n
+#undef FLAG_d
+#undef FLAG_C
+#undef FLAG_c
+#undef FLAG_b
+#endif
+
// hexedit <1>1r
#undef OPTSTR_hexedit
#define OPTSTR_hexedit "<1>1r"
@@ -2256,9 +2273,9 @@
#undef FLAG_c
#endif
-// pidof <1so:x
+// pidof so:x
#undef OPTSTR_pidof
-#define OPTSTR_pidof "<1so:x"
+#define OPTSTR_pidof "so:x"
#ifdef CLEANUP_pidof
#undef CLEANUP_pidof
#undef FOR_pidof
@@ -4709,6 +4726,21 @@
#define FLAG_a (FORCED_FLAG<<2)
#endif
+#ifdef FOR_hexdump
+#ifndef TT
+#define TT this.hexdump
+#endif
+#define FLAG_x (FORCED_FLAG<<0)
+#define FLAG_v (FORCED_FLAG<<1)
+#define FLAG_s (FORCED_FLAG<<2)
+#define FLAG_o (FORCED_FLAG<<3)
+#define FLAG_n (FORCED_FLAG<<4)
+#define FLAG_d (FORCED_FLAG<<5)
+#define FLAG_C (FORCED_FLAG<<6)
+#define FLAG_c (FORCED_FLAG<<7)
+#define FLAG_b (FORCED_FLAG<<8)
+#endif
+
#ifdef FOR_hexedit
#ifndef TT
#define TT this.hexedit
diff --git a/android/mac/generated/globals.h b/android/mac/generated/globals.h
index 1eede5a7..cb866143 100644
--- a/android/mac/generated/globals.h
+++ b/android/mac/generated/globals.h
@@ -117,7 +117,7 @@ struct passwd_data {
// toys/lsb/pidof.c
struct pidof_data {
- char *omit;
+ char *o;
};
// toys/lsb/seq.c
@@ -722,6 +722,19 @@ struct groupadd_data {
long gid;
};
+// toys/pending/hexdump.c
+
+struct hexdump_data {
+ long s, n;
+
+ long long len, pos, ppos;
+ const char *fmt;
+ unsigned int fn, bc; // file number and byte count
+ char linebuf[16]; // line buffer - serves double duty for sqeezing repeat
+ // lines and for accumulating full lines accross file
+ // boundaries if necessesary.
+};
+
// toys/pending/host.c
struct host_data {
@@ -1676,6 +1689,7 @@ extern union global_union {
struct getopt_data getopt;
struct getty_data getty;
struct groupadd_data groupadd;
+ struct hexdump_data hexdump;
struct host_data host;
struct ip_data ip;
struct ipcrm_data ipcrm;
diff --git a/android/mac/generated/help.h b/android/mac/generated/help.h
index 8a9f3aa6..cd0919a2 100644
--- a/android/mac/generated/help.h
+++ b/android/mac/generated/help.h
@@ -72,7 +72,7 @@
#define HELP_seq "usage: seq [-w|-f fmt_str] [-s sep_str] [first] [increment] last\n\nCount from first to last, by increment. Omitted arguments default\nto 1. Two arguments are used as first and last. Arguments can be\nnegative or floating point.\n\n-f Use fmt_str as a printf-style floating point format string\n-s Use sep_str as separator, default is a newline character\n-w Pad to equal width with leading zeroes"
-#define HELP_pidof "usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME]...\n\nPrint the PIDs of all processes with the given names.\n\n-s Single shot, only return one pid\n-o Omit PID(s)\n-x Match shell scripts too"
+#define HELP_pidof "usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME...]\n\nPrint the PIDs of all processes with the given names.\n\n-o Omit PID(s)\n-s Single shot, only return one pid\n-x Match shell scripts too"
#define HELP_passwd_sad "Password changes are checked to make sure they're at least 6 chars long,\ndon't include the entire username (but not a subset of it), or the entire\nprevious password (but changing password1, password2, password3 is fine).\nThis heuristic accepts \"aaaaaa\" and \"123456\"."
@@ -432,6 +432,10 @@
#define HELP_host "usage: host [-av] [-t TYPE] NAME [SERVER]\n\nPerform DNS lookup on NAME, which can be a domain name to lookup,\nor an IPv4 dotted or IPv6 colon-separated address to reverse lookup.\nSERVER (if present) is the DNS server to use.\n\n-a -v -t ANY\n-t TYPE query records of type TYPE\n-v verbose"
+#define HELP_hd "usage: hd [FILE...]\n\nDisplay file(s) in cannonical hex+ASCII format."
+
+#define HELP_hexdump "usage: hexdump [-bcCdovx] [-n LEN] [-s SKIP] [FILE...]\n\nDump file(s) in hexadecimal format.\n\n-n LEN Show LEN bytes of output\n-s SKIP Skip bytes of input\n-v Verbose (don't combine identical lines)\n\nDisplay type:\n-b One byte octal -c One byte character -C Canonical (hex + ASCII)\n-d Two byte decimal -o Two byte octal -x Two byte hexadecimal (default)"
+
#define HELP_groupdel "usage: groupdel [USER] GROUP\n\nDelete a group or remove a user from a group"
#define HELP_groupadd "usage: groupadd [-S] [-g GID] [USER] GROUP\n\nAdd a group or add a user to a group\n\n -g GID Group id\n -S Create a system group"
diff --git a/android/mac/generated/newtoys.h b/android/mac/generated/newtoys.h
index ecbabab5..81d4725a 100644
--- a/android/mac/generated/newtoys.h
+++ b/android/mac/generated/newtoys.h
@@ -109,9 +109,11 @@ USE_GROUPS(NEWTOY(groups, NULL, TOYFLAG_USR|TOYFLAG_BIN))
USE_GUNZIP(NEWTOY(gunzip, "cdfk123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN))
USE_GZIP(NEWTOY(gzip, "ncdfk123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN))
USE_REBOOT(OLDTOY(halt, reboot, TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
+USE_HD(OLDTOY(hd, hexdump, TOYFLAG_USR|TOYFLAG_BIN))
USE_HEAD(NEWTOY(head, "?n(lines)#<0=10c(bytes)#<0qv[-nc]", TOYFLAG_USR|TOYFLAG_BIN))
USE_HELLO(NEWTOY(hello, 0, TOYFLAG_USR|TOYFLAG_BIN))
USE_HELP(NEWTOY(help, "ahu", TOYFLAG_BIN|TOYFLAG_MAYFORK))
+USE_HEXDUMP(NEWTOY(hexdump, "bcCdn#<0os#<0vx[!bcCdox]", TOYFLAG_USR|TOYFLAG_BIN))
USE_HEXEDIT(NEWTOY(hexedit, "<1>1r", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
USE_HOST(NEWTOY(host, "<1>2avt:", TOYFLAG_USR|TOYFLAG_BIN))
USE_HOSTID(NEWTOY(hostid, ">0", TOYFLAG_USR|TOYFLAG_BIN))
@@ -199,7 +201,7 @@ USE_PASSWD(NEWTOY(passwd, ">1a:dlu", TOYFLAG_STAYROOT|TOYFLAG_USR|TOYFLAG_BIN))
USE_PASTE(NEWTOY(paste, "d:s", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
USE_PATCH(NEWTOY(patch, ">2(no-backup-if-mismatch)(dry-run)"USE_TOYBOX_DEBUG("x")"F#g#fulp#d:i:Rs(quiet)", TOYFLAG_USR|TOYFLAG_BIN))
USE_PGREP(NEWTOY(pgrep, "?cld:u*U*t*s*P*g*G*fnovxL:[-no]", TOYFLAG_USR|TOYFLAG_BIN))
-USE_PIDOF(NEWTOY(pidof, "<1so:x", TOYFLAG_BIN))
+USE_PIDOF(NEWTOY(pidof, "so:x", TOYFLAG_BIN))
USE_PING(NEWTOY(ping, "<1>1m#t#<0>255=64c#<0=3s#<0>4064=56i%W#<0=3w#<0qf46I:[-46]", TOYFLAG_USR|TOYFLAG_BIN))
USE_PING(OLDTOY(ping6, ping, TOYFLAG_USR|TOYFLAG_BIN))
USE_PIVOT_ROOT(NEWTOY(pivot_root, "<2>2", TOYFLAG_SBIN))
diff --git a/configure b/configure
index 0b6501fc..8e40814e 100755
--- a/configure
+++ b/configure
@@ -21,8 +21,10 @@ CFLAGS="$CFLAGS -funsigned-char"
[ -z "$ASAN" ] || { CFLAGS="$CFLAGS -O1 -g -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=address"; NOSTRIP=1; }
# We accept LDFLAGS, but by default don't have anything in it
-if [ "$(uname)" != "Darwin" ]
+if [ "$(uname)" == "Darwin" ]
then
+ [ -z "$LDOPTIMIZE" ] && LDOPTIMIZE="-Wl,-dead_strip"
+else
[ -z "$LDOPTIMIZE" ] && LDOPTIMIZE="-Wl,--gc-sections"
LDASNEEDED="-Wl,--as-needed"
fi
diff --git a/lib/lib.c b/lib/lib.c
index 332a0d01..0c1b5c37 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1164,9 +1164,10 @@ void names_to_pid(char **names, int (*callback)(pid_t pid, char *name),
if (scripts && !strcmp(bb, getbasename(cmd+strlen(cmd)+1))) goto match;
continue;
match:
- if (callback(u, *cur)) break;
+ if (callback(u, *cur)) goto done;
}
}
+done:
closedir(dp);
}
diff --git a/lib/portability.h b/lib/portability.h
index 7d8334b8..5ddfea5c 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -197,7 +197,7 @@ void *memmem(const void *haystack, size_t haystack_length,
#include <sys/personality.h>
#else
#define PER_LINUX32 0
-#define personality(x)
+int personality(int);
#endif
#if defined(__APPLE__) || defined(__linux__)
diff --git a/tests/hexdump.test b/tests/hexdump.test
new file mode 100755
index 00000000..e319957c
--- /dev/null
+++ b/tests/hexdump.test
@@ -0,0 +1,135 @@
+#!/bin/bash
+
+[ -f testing.sh ] && . testing.sh
+
+testcmd "simple file" "input" "0000000 6973 706d 656c 000a\n0000007\n" "simple\\n" ""
+testcmd "simple file -b" "-b input" "0000000 163 151 155 160 154 145 012\n0000007\n" "simple\\n" ""
+testcmd "simple file -c" "-c input" "0000000 s i m p l e \\\\n\n0000007\n" "simple\\n" ""
+testcmd "simple file -d" "-d input" "0000000 26995 28781 25964 00010\n0000007\n" "simple\\n" ""
+testcmd "simple file -o" "-o input" "0000000 064563 070155 062554 000012\n0000007\n" "simple\\n" ""
+testcmd "simple file -x" "-x input" "0000000 6973 706d 656c 000a\n0000007\n" "simple\\n" ""
+
+testcmd \
+ "simple file canonical output -C" \
+ "-C input" \
+ "\
+00000000 73 69 6d 70 6c 65 0a |simple.|\n\
+00000007\n" \
+ "simple\n" \
+ ""
+testcmd \
+ "simple file canonical output -C multiline" \
+ "-C input" \
+ "\
+00000000 73 69 6d 70 6c 65 0a 62 61 72 66 6f 6f 62 61 72 |simple.barfoobar|\n\
+00000010 66 6f 6f 62 61 72 0a |foobar.|\n\
+00000017\n" \
+ "\
+simple\n\
+barfoobarfoobar\n" \
+ ""
+
+testcmd \
+ "head of file -n 10" \
+ "-n 10 input" \
+ "\
+0000000 6973 706d 656c 730a 6d69\n\
+000000a\n" \
+ "simple\nsimple\n" \
+ ""
+testcmd \
+ "skip head of file -s 10" \
+ "-s 10 input" \
+ "\
+000000a 6c70 0a65\n\
+000000e\n" \
+ "simple\nsimple\n" \
+ ""
+
+testcmd \
+ "squeeze repeating lines" \
+ "input" \
+ "\
+0000000 6161 6161 6161 6161 6161 6161 6161 0a61\n\
+*\n\
+0000070 6f66 006f\n\
+0000073\n" \
+ "\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+foo" \
+ ""
+testcmd \
+ "squeeze repeating lines" \
+ "input" \
+ "\
+0000000 6161 6161 6161 6161 6161 6161 6161 0a61\n\
+*\n\
+0000030 6262 6262 6262 6262 6262 6262 6262 0a62\n\
+0000040 6161 6161 6161 6161 6161 6161 6161 0a61\n\
+*\n\
+0000070 6262 6262 6262 6262 6262 6262 6262 0a62\n\
+0000080\n" \
+ "\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+bbbbbbbbbbbbbbb\n\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+bbbbbbbbbbbbbbb\n" \
+ ""
+testcmd \
+ "don't squeeze repeating lines" \
+ "-v input" \
+ "\
+0000000 6161 6161 6161 6161 6161 6161 6161 0a61\n\
+0000010 6161 6161 6161 6161 6161 6161 6161 0a61\n\
+0000020 6161 6161 6161 6161 6161 6161 6161 0a61\n\
+0000030 6161 6161 6161 6161 6161 6161 6161 0a61\n\
+0000040 6161 6161 6161 6161 6161 6161 6161 0a61\n\
+0000050 6161 6161 6161 6161 6161 6161 6161 0a61\n\
+0000060 6161 6161 6161 6161 6161 6161 6161 0a61\n\
+0000070 6f66 006f\n\
+0000073\n" \
+ "\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+aaaaaaaaaaaaaaa\n\
+foo" \
+ ""
+
+for _ in {1..25}; do echo "foobar" >> file1; done
+for _ in {1..25}; do echo "buzzbar" >> file2; done
+
+testcmd \
+ "accumulate offset accross files" \
+ "file1 file2" \
+ "0000000 6f66 626f 7261 660a 6f6f 6162 0a72 6f66\n\
+0000010 626f 7261 660a 6f6f 6162 0a72 6f66 626f\n\
+0000020 7261 660a 6f6f 6162 0a72 6f66 626f 7261\n\
+0000030 660a 6f6f 6162 0a72 6f66 626f 7261 660a\n\
+0000040 6f6f 6162 0a72 6f66 626f 7261 660a 6f6f\n\
+0000050 6162 0a72 6f66 626f 7261 660a 6f6f 6162\n\
+0000060 0a72 6f66 626f 7261 660a 6f6f 6162 0a72\n\
+0000070 6f66 626f 7261 660a 6f6f 6162 0a72 6f66\n\
+0000080 626f 7261 660a 6f6f 6162 0a72 6f66 626f\n\
+0000090 7261 660a 6f6f 6162 0a72 6f66 626f 7261\n\
+00000a0 660a 6f6f 6162 0a72 6f66 626f 7261 620a\n\
+00000b0 7a75 627a 7261 620a 7a75 627a 7261 620a\n\
+*\n\
+0000170 7a75 627a 7261 000a\n\
+0000177\n" \
+ "" \
+ ""
+rm file1 file2
diff --git a/toys/lsb/pidof.c b/toys/lsb/pidof.c
index cd705a7c..791eed05 100644
--- a/toys/lsb/pidof.c
+++ b/toys/lsb/pidof.c
@@ -5,18 +5,18 @@
*
* http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/pidof.html
-USE_PIDOF(NEWTOY(pidof, "<1so:x", TOYFLAG_BIN))
+USE_PIDOF(NEWTOY(pidof, "so:x", TOYFLAG_BIN))
config PIDOF
bool "pidof"
default y
help
- usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME]...
+ usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME...]
Print the PIDs of all processes with the given names.
- -s Single shot, only return one pid
-o Omit PID(s)
+ -s Single shot, only return one pid
-x Match shell scripts too
*/
@@ -24,17 +24,17 @@ config PIDOF
#include "toys.h"
GLOBALS(
- char *omit;
+ char *o;
)
static int print_pid(pid_t pid, char *name)
{
sprintf(toybuf, "%d", (int)pid);
- if (comma_scan(TT.omit, toybuf, 0)) return 0;
+ if (comma_scan(TT.o, toybuf, 0)) return 0;
xprintf(" %s"+!!toys.exitval, toybuf);
toys.exitval = 0;
- return toys.optflags & FLAG_s;
+ return FLAG(s);
}
void pidof_main(void)
diff --git a/toys/pending/hexdump.c b/toys/pending/hexdump.c
new file mode 100644
index 00000000..5e367a2a
--- /dev/null
+++ b/toys/pending/hexdump.c
@@ -0,0 +1,155 @@
+/* hexdump.c - Dump file content in hexadecimal format to stdout
+ *
+ * Copyright 2021 Moritz Röhrich <moritz@ildefons.de>
+ *
+ * No standard
+ *
+ * TODO:
+ * - Implement format strings (see man (1) hexdump)
+
+USE_HEXDUMP(NEWTOY(hexdump, "bcCdn#<0os#<0vx[!bcCdox]", TOYFLAG_USR|TOYFLAG_BIN))
+USE_HD(OLDTOY(hd, hexdump, TOYFLAG_USR|TOYFLAG_BIN))
+
+config HEXDUMP
+ bool "hexdump"
+ default n
+ help
+ usage: hexdump [-bcCdovx] [-n LEN] [-s SKIP] [FILE...]
+
+ Dump file(s) in hexadecimal format.
+
+ -n LEN Show LEN bytes of output
+ -s SKIP Skip bytes of input
+ -v Verbose (don't combine identical lines)
+
+ Display type:
+ -b One byte octal -c One byte character -C Canonical (hex + ASCII)
+ -d Two byte decimal -o Two byte octal -x Two byte hexadecimal (default)
+
+config HD
+ bool "hd"
+ default HEXDUMP
+ help
+ usage: hd [FILE...]
+
+ Display file(s) in cannonical hex+ASCII format.
+*/
+
+#define FOR_hexdump
+#include "toys.h"
+
+GLOBALS(
+ long s, n;
+
+ long long len, pos, ppos;
+ const char *fmt;
+ unsigned int fn, bc; // file number and byte count
+ char linebuf[16]; // line buffer - serves double duty for sqeezing repeat
+ // lines and for accumulating full lines accross file
+ // boundaries if necessesary.
+)
+
+const char *make_printable(unsigned char byte) {
+ switch (byte) {
+ case '\0': return "\\0";
+ case '\a': return "\\a";
+ case '\b': return "\\b";
+ case '\t': return "\\t";
+ case '\n': return "\\n";
+ case '\v': return "\\v";
+ case '\f': return "\\f";
+ default: return "??"; // for all unprintable bytes
+ }
+}
+
+void do_hexdump(int fd, char *name)
+{
+ unsigned short block, adv, i;
+ int sl, fs; // skip line, file size
+
+ TT.fn++; // keep track of how many files have been printed.
+ // skipp ahead, if necessary skip entire files:
+ if (FLAG(s) && (TT.s-TT.pos>0)) {
+ fs = xlseek(fd, 0L, SEEK_END);
+
+ if (fs < TT.s) {
+ TT.pos += fs;
+ TT.ppos += fs;
+ } else {
+ xlseek(fd, TT.s-TT.pos, SEEK_SET);
+ TT.ppos = TT.s;
+ TT.pos = TT.s;
+ }
+ }
+
+ for (sl = 0;
+ 0 < (TT.len = readall(fd, toybuf,
+ (TT.n && TT.s+TT.n-TT.pos<16-(TT.bc%16))
+ ? TT.s+TT.n-TT.pos : 16-(TT.bc%16)));
+ TT.pos += TT.len) {
+ // This block compares the data read from file to the last line printed.
+ // If they don't match a new line is printed, else the line is skipped.
+ // If a * has already been printed to indicate a skipped line, printing the
+ // * is also skipped.
+ for (i = 0; i < 16 && i < TT.len; i++){
+ if (FLAG(v) || TT.len < 16 || toybuf[i] != TT.linebuf[i]) goto newline;
+ }
+ if (sl == 0) {
+ printf("*\n");
+ sl = 1;
+ }
+ TT.ppos += TT.len;
+ continue;
+
+newline:
+ strncpy(TT.linebuf+(TT.bc%16), toybuf, TT.len);
+ TT.bc = TT.bc % 16 + TT.len;
+ sl = 0;
+ if (TT.pos + TT.bc == TT.s+TT.n || TT.fn == toys.optc || TT.bc == 16) {
+ if (!FLAG(C) && !FLAG(c)) {
+ printf("%07llx", TT.ppos);
+ adv = FLAG(b) ? 1 : 2;
+ for (i = 0; i < TT.bc; i += adv) {
+ block = (FLAG(b) || i == TT.bc-1)
+ ? TT.linebuf[i] : (TT.linebuf[i] | TT.linebuf[i+1] << 8);
+ printf(TT.fmt, block);
+ }
+ } else if (FLAG(C)) {
+ printf("%08llx", TT.ppos);
+ for (i = 0; i < 16; i++) {
+ if (!(i % 8)) putchar(' ');
+ if (i < TT.bc) printf(" %02x", TT.linebuf[i]);
+ else printf(" ");
+ }
+ printf(" |");
+ for (i = 0; i < TT.bc; i++) {
+ if (TT.linebuf[i] < ' ' || TT.linebuf[i] > '~') putchar('.');
+ else putchar(TT.linebuf[i]);
+ }
+ putchar('|');
+ } else {
+ printf("%07llx", TT.ppos);
+ for (i = 0; i < TT.bc; i++) {
+ if (TT.linebuf[i] >= ' ' && TT.linebuf[i] <= '~')
+ printf("%4c", TT.linebuf[i]);
+ else printf("%4s", make_printable(TT.linebuf[i]));
+ }
+ }
+ putchar('\n');
+ TT.ppos += TT.bc;
+ }
+ }
+
+ if (TT.len < 0) perror_exit("read");
+}
+
+void hexdump_main(void)
+{
+ if FLAG(b) TT.fmt = " %03o";
+ else if FLAG(d) TT.fmt = " %05d";
+ else if FLAG(o) TT.fmt = " %06o";
+ else TT.fmt = " %04x";
+
+ loopfiles(toys.optargs, do_hexdump);
+ FLAG(C) ? printf("%08llx\n", TT.pos) : printf("%07llx\n", TT.pos);
+}