[PATCH v2 1/8] tests: print quotation marks in print_quoted_memory

JingPiao Chen chenjingpiao at gmail.com
Fri Jul 7 03:23:47 UTC 2017


* tests/print_quoted_string.c (print_quoted_memory): Add
quotation marks printer.
* tests/getcwd.c (main): Remove quotation marks printer.
* tests/keyctl.c (print_quoted_string_limit): Likewise.
* tests/netlink_protocol.c (send_query): Likewise.
* tests/uname.c (main): Likewise.
* tests/xattr.c (main): Likewise.
---
 tests/getcwd.c              |  4 ++--
 tests/keyctl.c              | 10 ++--------
 tests/netlink_protocol.c    |  4 ++--
 tests/print_quoted_string.c |  2 ++
 tests/uname.c               | 15 +++++++--------
 tests/xattr.c               |  2 --
 6 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/tests/getcwd.c b/tests/getcwd.c
index 707c25c..0c32f8d 100644
--- a/tests/getcwd.c
+++ b/tests/getcwd.c
@@ -20,9 +20,9 @@ main(void)
 	if (res <= 0)
 		perror_msg_and_fail("getcwd");
 
-	printf("getcwd(\"");
+	printf("getcwd(");
 	print_quoted_string(cur_dir);
-	printf("\", %zu) = %ld\n", sizeof(cur_dir), res);
+	printf(", %zu) = %ld\n", sizeof(cur_dir), res);
 
 	res = syscall(__NR_getcwd, cur_dir, 0);
 	printf("getcwd(%p, 0) = %s\n", cur_dir, sprintrc(res));
diff --git a/tests/keyctl.c b/tests/keyctl.c
index 492c62a..bfc6d50 100644
--- a/tests/keyctl.c
+++ b/tests/keyctl.c
@@ -97,17 +97,11 @@ print_quoted_string_limit(const char *str, size_t size, long rc)
 
 	if (!nul_terminated_buf ||
 	    (strnlen(str, limited_size) == limited_size)) {
-		printf("\"");
 		print_quoted_memory(str, limited_size);
 		if (print_size > limit)
-			printf("\"...");
-		else
-			printf("\"");
-	} else {
-		printf("\"");
+			printf("...");
+	} else
 		print_quoted_string(str);
-		printf("\"");
-	}
 }
 
 static void
diff --git a/tests/netlink_protocol.c b/tests/netlink_protocol.c
index f09dd9a..eadc14f 100644
--- a/tests/netlink_protocol.c
+++ b/tests/netlink_protocol.c
@@ -150,11 +150,11 @@ send_query(const int fd)
 		    NULL, 0);
 	errstr = sprintrc(rc);
 	printf("sendto(%d, [{{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
-	       ", seq=0, pid=0}, \"abcd\"}, \"",
+	       ", seq=0, pid=0}, \"abcd\"}, ",
 	       fd, reqs->req1.nlh.nlmsg_len, NLM_F_DUMP);
 	print_quoted_memory((void *) &reqs->req2.nlh,
 			    sizeof(reqs->req2) - sizeof(req->nlh));
-	printf("\"], %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+	printf("], %u, MSG_DONTWAIT, NULL, 0) = %s\n",
 	       (unsigned) (sizeof(*reqs) - sizeof(req->nlh)), errstr);
 
 	/* second nlmsg_len < sizeof(struct nlmsghdr) */
diff --git a/tests/print_quoted_string.c b/tests/print_quoted_string.c
index 732fe3d..ea87d11 100644
--- a/tests/print_quoted_string.c
+++ b/tests/print_quoted_string.c
@@ -21,6 +21,7 @@ print_quoted_memory(const char *instr, const size_t len)
 	const unsigned char *str = (const unsigned char *) instr;
 	size_t i;
 
+	putchar('"');
 	for (i = 0; i < len; ++i) {
 		const int c = str[i];
 		switch (c) {
@@ -72,4 +73,5 @@ print_quoted_memory(const char *instr, const size_t len)
 		}
 	}
 
+	putchar('"');
 }
diff --git a/tests/uname.c b/tests/uname.c
index 96db753..23b64c1 100644
--- a/tests/uname.c
+++ b/tests/uname.c
@@ -12,24 +12,23 @@ int main(int ac, char **av)
 	int abbrev = ac > 1;
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct utsname, uname);
 	int rc = syscall(__NR_uname, uname);
-	printf("uname({sysname=\"");
+	printf("uname({sysname=");
 	print_quoted_string(uname->sysname);
-	printf("\", nodename=\"");
+	printf(", nodename=");
 	print_quoted_string(uname->nodename);
 	if (abbrev) {
-		printf("\", ...");
+		printf(", ...");
 	} else {
-		printf("\", release=\"");
+		printf(", release=");
 		print_quoted_string(uname->release);
-		printf("\", version=\"");
+		printf(", version=");
 		print_quoted_string(uname->version);
-		printf("\", machine=\"");
+		printf(", machine=");
 		print_quoted_string(uname->machine);
 # ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME
-		printf("\", domainname=\"");
+		printf(", domainname=");
 		print_quoted_string(uname->domainname);
 # endif
-		printf("\"");
 	}
 	printf("}) = %d\n", rc);
 
diff --git a/tests/xattr.c b/tests/xattr.c
index 03b4270..fea9e92 100644
--- a/tests/xattr.c
+++ b/tests/xattr.c
@@ -112,9 +112,7 @@ main(void)
 	else {
 		const int ellipsis = rc > DEFAULT_STRLEN;
 
-		putchar('"');
 		print_quoted_memory(big, ellipsis ? DEFAULT_STRLEN : rc);
-		putchar('"');
 		if (ellipsis)
 			fputs("...", stdout);
 	}
-- 
2.7.4





More information about the Strace-devel mailing list