]> granicus.if.org Git - strace/commitdiff
tests: add print_quoted_stringn to print string with a size limit
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sun, 10 Jun 2018 10:52:52 +0000 (12:52 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 11 Jun 2018 14:02:06 +0000 (14:02 +0000)
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.

tests/print_quoted_string.c
tests/tests.h

index 3ca56318e849bd94d651736b725c257a289434ef..a58b69ac47726b3114b0183daeb209dd90554e1d 100644 (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)
 {
index 9b829ea36dce4f14bf30b9422913140ebfd74e57..248e341ca79a76539a73413c8ca661434336a270 100644 (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);