From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Jones Subject: [kvm-unit-tests PATCH v5 06/18] lib: add vprintf Date: Wed, 17 Feb 2016 19:40:47 +0100 Message-ID: <1455734459-31902-7-git-send-email-drjones@redhat.com> References: <1455734459-31902-1-git-send-email-drjones@redhat.com> Cc: thuth@redhat.com, dgibson@redhat.com, david@gibson.dropbear.id.au, agraf@suse.de, lvivier@redhat.com, pbonzini@redhat.com, rkrcmar@redhat.com To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:35560 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422865AbcBQSlU (ORCPT ); Wed, 17 Feb 2016 13:41:20 -0500 In-Reply-To: <1455734459-31902-1-git-send-email-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: va_report_xfail has the pattern char buf[] vsnprintf(buf, ...) puts(buf) Before adding another one, replace it with vprintf. Suggested-by: David Gibson Signed-off-by: Andrew Jones --- lib/libcflat.h | 1 + lib/printf.c | 14 +++++++++++++- lib/report.c | 4 +--- 3 files changed, 15 insertions(+), 4 deletions(-) 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++; -- 2.4.3