From: Eugene Syromyatnikov Date: Fri, 6 Jan 2017 08:55:30 +0000 (+0100) Subject: util: add support for forcing printing string as hex-escaped X-Git-Tag: v4.16~87 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=34a920baadf2786773e6b6aecf7e2476bb0ac216;p=strace util: add support for forcing printing string as hex-escaped 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. --- diff --git a/defs.h b/defs.h index 9deb6926..0a39650f 100644 --- 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 16e3b51f..a38f8217 100644 --- 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) {