[kvm-unit-tests,v7,06/18] lib: add vprintf
diff mbox

Message ID 1456750072-7524-7-git-send-email-drjones@redhat.com
State Accepted
Headers show

Commit Message

Andrew Jones Feb. 29, 2016, 12:47 p.m. UTC
va_report_xfail has the pattern

 char buf[]
 vsnprintf(buf, ...)
 puts(buf)

Before adding another one, replace it with vprintf.

Suggested-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Thomas Huth <thuth@redhat.com>
---
 lib/libcflat.h |  1 +
 lib/printf.c   | 14 +++++++++++++-
 lib/report.c   |  4 +---
 3 files changed, 15 insertions(+), 4 deletions(-)

Patch
diff mbox

diff --git a/lib/libcflat.h b/lib/libcflat.h
index 9747ccdbc9f1d..f7a5728c6759a 100644
--- a/lib/libcflat.h
+++ b/lib/libcflat.h
@@ -55,6 +55,7 @@  extern void abort(void);
 extern int printf(const char *fmt, ...);
 extern int snprintf(char *buf, int size, const char *fmt, ...);
 extern int vsnprintf(char *buf, int size, const char *fmt, va_list va);
+extern int vprintf(const char *fmt, va_list va);
 extern long atol(const char *ptr);
 
 void report_prefix_push(const char *prefix);
diff --git a/lib/printf.c b/lib/printf.c
index 5d83605afe829..2aec59aa6d6d4 100644
--- a/lib/printf.c
+++ b/lib/printf.c
@@ -1,5 +1,7 @@ 
 #include "libcflat.h"
 
+#define BUFSZ 2000
+
 typedef struct pstream {
     char *buffer;
     int remain;
@@ -235,10 +237,20 @@  int snprintf(char *buf, int size, const char *fmt, ...)
     return r;
 }
 
+int vprintf(const char *fmt, va_list va)
+{
+    char buf[BUFSZ];
+    int r;
+
+    r = vsnprintf(buf, sizeof(buf), fmt, va);
+    puts(buf);
+    return r;
+}
+
 int printf(const char *fmt, ...)
 {
     va_list va;
-    char buf[2000];
+    char buf[BUFSZ];
     int r;
 
     va_start(va, fmt);
diff --git a/lib/report.c b/lib/report.c
index 35e664108a921..c29e835b9c751 100644
--- a/lib/report.c
+++ b/lib/report.c
@@ -47,15 +47,13 @@  void va_report_xfail(const char *msg_fmt, bool xfail, bool cond, va_list va)
 {
 	char *pass = xfail ? "XPASS" : "PASS";
 	char *fail = xfail ? "XFAIL" : "FAIL";
-	char buf[2000];
 
 	spin_lock(&lock);
 
 	tests++;
 	printf("%s: ", cond ? pass : fail);
 	puts(prefixes);
-	vsnprintf(buf, sizeof(buf), msg_fmt, va);
-	puts(buf);
+	vprintf(msg_fmt, va);
 	puts("\n");
 	if (xfail && cond)
 		failures++;