]> granicus.if.org Git - strace/commitdiff
tests: add print_quoted_memory function to libtests
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 10 May 2016 22:05:53 +0000 (22:05 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 10 May 2016 22:12:01 +0000 (22:12 +0000)
* tests/print_quoted_string.c (print_quoted_memory): New function.
(print_quoted_string): Use it.
* tests/tests.h (print_quoted_memory): New prototype.

tests/print_quoted_string.c
tests/tests.h

index 18a9ccfbfaf49e0de5c38aaf248b29759837c298..3ad86024c228cc2ee598f5bdf17bae75331e7e8f 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 /*
  * Based on string_quote() from util.c.
 
 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("\\\"");
index 8c466bfd4435a51261c5a9abb82964c530921ef9..9909222f1588ac37968f8d511b074eaa55cc4029 100644 (file)
@@ -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 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);