]> granicus.if.org Git - strace/commitdiff
util: add support for forcing printing string as hex-escaped
authorEugene Syromyatnikov <evgsyr@gmail.com>
Fri, 6 Jan 2017 08:55:30 +0000 (09:55 +0100)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 6 Jan 2017 11:39:54 +0000 (11:39 +0000)
This could be useful in cases when some binary data should not be
interpreted as an ASCII string, but rather as an array of byte values.

* defs.h (QUOTE_FORCE_HEX): New macro constant.
* util.c (quote_string): Enable use_hex when QUOTE_FORCE_HEX is set
in user_style parameter.

defs.h
util.c

diff --git a/defs.h b/defs.h
index 9deb69268ae09903370d2e6efcdc016b62500423..0a39650fe3dd3526a8551390c7c9744c1d7480be 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -505,6 +505,7 @@ extern int next_set_bit(const void *bit_array, unsigned cur_bit, unsigned size_b
 #define QUOTE_0_TERMINATED                      0x01
 #define QUOTE_OMIT_LEADING_TRAILING_QUOTES      0x02
 #define QUOTE_OMIT_TRAILING_0                   0x08
+#define QUOTE_FORCE_HEX                         0x10
 
 extern int string_quote(const char *, char *, unsigned int, unsigned int);
 extern int print_quoted_string(const char *, unsigned int, unsigned int);
diff --git a/util.c b/util.c
index 16e3b51fa27e78aa4f69c3a11c88628dd5e90200..a38f82174136d6adba193fab7bbb28ac7905e258 100644 (file)
--- a/util.c
+++ b/util.c
@@ -654,9 +654,9 @@ string_quote(const char *instr, char *outstr, const unsigned int size,
                eol = 0x100; /* this can never match a char */
 
        usehex = 0;
-       if (xflag > 1)
+       if ((xflag > 1) || (style & QUOTE_FORCE_HEX)) {
                usehex = 1;
-       else if (xflag) {
+       else if (xflag) {
                /* Check for presence of symbol which require
                   to hex-quote the whole string. */
                for (i = 0; i < size; ++i) {