From: Dmitry V. Levin Date: Tue, 10 May 2016 22:05:53 +0000 (+0000) Subject: tests: add print_quoted_memory function to libtests X-Git-Tag: v4.12~191 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=72cb81151f2262bc2062cc1cdf7d4a7e768c4b15;p=strace tests: add print_quoted_memory function to libtests * tests/print_quoted_string.c (print_quoted_memory): New function. (print_quoted_string): Use it. * tests/tests.h (print_quoted_memory): New prototype. --- diff --git a/tests/print_quoted_string.c b/tests/print_quoted_string.c index 18a9ccfb..3ad86024 100644 --- a/tests/print_quoted_string.c +++ b/tests/print_quoted_string.c @@ -2,6 +2,7 @@ #include #include +#include /* * Based on string_quote() from util.c. @@ -10,11 +11,18 @@ void print_quoted_string(const char *instr) +{ + print_quoted_memory(instr, strlen(instr)); +} + +void +print_quoted_memory(const char *instr, const size_t len) { const unsigned char *str = (const unsigned char*) instr; - int c; + size_t i; - while ((c = *(str++))) { + for (i = 0; i < len; ++i) { + const int c = str[i]; switch (c) { case '\"': printf("\\\""); diff --git a/tests/tests.h b/tests/tests.h index 8c466bfd..9909222f 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -78,9 +78,12 @@ const char *hexquote_strndup(const char *, size_t); /* Return inode number of socket descriptor. */ unsigned long inode_of_sockfd(int); -/* Print string in quoted form. */ +/* Print string in a quoted form. */ void print_quoted_string(const char *); +/* Print memory in a quoted form. */ +void print_quoted_memory(const char *, size_t); + /* Check whether given uid matches kernel overflowuid. */ void check_overflowuid(const int);