tests: add print_quoted_stringn to print string with a size limit

This is similar to print_quoted_cstring, but not quite the same.

* tests/print_quoted_string.c (print_quoted_stringn): New function.
* tests/tests.h (print_quoted_stringn): New declaration.
This commit is contained in:
Eugene Syromyatnikov 2018-06-10 12:52:52 +02:00 committed by Dmitry V. Levin
parent b178553f22
commit 418625eaaa
2 changed files with 18 additions and 0 deletions

View File

@ -33,6 +33,18 @@ print_quoted_cstring(const char *instr, const size_t size)
}
}
void
print_quoted_stringn(const char *instr, const size_t size)
{
const size_t len = strnlen(instr, size);
if (len < size) {
print_quoted_memory(instr, len);
} else {
print_quoted_memory(instr, size);
printf("...");
}
}
static void
print_octal(unsigned char c, char next)
{

View File

@ -174,6 +174,12 @@ void print_quoted_string(const char *);
*/
void print_quoted_cstring(const char *str, size_t size);
/*
* Print a NUL-terminated string `str' of length up to `size'
* in a quoted form.
*/
void print_quoted_stringn(const char *str, size_t size);
/* Print memory in a quoted form with optional escape characters. */
void print_quoted_memory_ex(const void *, size_t, bool quote,
const char *escape_chars);