summaryrefslogtreecommitdiff
path: root/util-linux/hexdump_xxd.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/hexdump_xxd.c')
-rw-r--r--util-linux/hexdump_xxd.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/util-linux/hexdump_xxd.c b/util-linux/hexdump_xxd.c
index 29bbc66..817250c 100644
--- a/util-linux/hexdump_xxd.c
+++ b/util-linux/hexdump_xxd.c
@@ -41,7 +41,7 @@
// -u use upper case hex letters.
//usage:#define xxd_trivial_usage
-//usage: "[-pr] [-g N] [-c N] [-n LEN] [-s OFS] [FILE]"
+//usage: "[-pr] [-g N] [-c N] [-n LEN] [-s OFS] [-o OFS] [FILE]"
//usage:#define xxd_full_usage "\n\n"
//usage: "Hex dump FILE (or stdin)\n"
//usage: "\n -g N Bytes per group"
@@ -50,6 +50,7 @@
// exactly the same help text lines in hexdump and xxd:
//usage: "\n -l LENGTH Show only first LENGTH bytes"
//usage: "\n -s OFFSET Skip OFFSET bytes"
+//usage: "\n -o OFFSET Add OFFSET to displayed offset"
//usage: "\n -r Reverse (with -p, assumes no offsets in input)"
#include "libbb.h"
@@ -62,6 +63,9 @@
#define OPT_a (1 << 2)
#define OPT_p (1 << 3)
#define OPT_r (1 << 4)
+#define OPT_g (1 << 5)
+#define OPT_c (1 << 6)
+#define OPT_o (1 << 7)
static void reverse(unsigned opt, unsigned cols, const char *filename)
{
@@ -127,15 +131,15 @@ int xxd_main(int argc UNUSED_PARAM, char **argv)
{
char buf[80];
dumper_t *dumper;
- char *opt_l, *opt_s;
+ char *opt_l, *opt_s, *opt_o;
unsigned bytes = 2;
unsigned cols = 0;
unsigned opt;
dumper = alloc_dumper();
- opt = getopt32(argv, "^" "l:s:aprg:+c:+" "\0" "?1" /* 1 argument max */,
- &opt_l, &opt_s, &bytes, &cols
+ opt = getopt32(argv, "^" "l:s:aprg:+c:+o:" "\0" "?1" /* 1 argument max */,
+ &opt_l, &opt_s, &bytes, &cols, &opt_o
);
argv += optind;
@@ -158,6 +162,11 @@ int xxd_main(int argc UNUSED_PARAM, char **argv)
//BUGGY for /proc/version (unseekable?)
}
+ if (opt & OPT_o) {
+ /* -o accepts negative numbers too */
+ dumper->xxd_displayoff = xstrtoll(opt_o, /*base:*/ 0);
+ }
+
if (opt & OPT_p) {
if (cols == 0)
cols = 30;
@@ -206,7 +215,7 @@ int xxd_main(int argc UNUSED_PARAM, char **argv)
bb_dump_add(dumper, buf);
} else {
bb_dump_add(dumper, "\"\n\"");
- dumper->eofstring = "\n";
+ dumper->xxd_eofstring = "\n";
}
return bb_dump_dump(dumper, argv);