From nobody Mon Nov 10 09:50:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1555529778; cv=none; d=zoho.com; s=zohoarc; b=YIt8cAGOy0sXATEOPB2KrwR96pSOHThg8aOP4U+7ooe13C9qDMzRl8Be4HIMbtWZ1dsresAf9+j47ALt2zC7r3K+91KGcUwnuZk/+RChdNerSB9onsqW69pqfhJZuT+A8mUUa+eDPabqwrhXOQjkhCY85/07Ji60S1lnwyMwWXg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555529778; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=du19n+SBTxy9lgBH5r0wC96HCzVVnGl0HlpPUuCg5JM=; b=ehT4Wim0WOPqwQaGyMYUkpex3Z3Jwe6T/uDgwP9tpWh56lC+BXZGgmU4a8RU7ms2l/n/0Rc3TS642Jpd8be3q8OmvtCyx0tdK9hW8tzZKuKOlPfj14Dpg1rTFHmkUbnZ7s/PTTvjzRKkFrRfaNbCCWP2HghtpN2fl4nPotzQxcc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155552977860847.12219131124482; Wed, 17 Apr 2019 12:36:18 -0700 (PDT) Received: from localhost ([127.0.0.1]:58565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGqLu-0005Wx-GX for importer@patchew.org; Wed, 17 Apr 2019 15:36:14 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34853) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGq4a-00004r-OT for qemu-devel@nongnu.org; Wed, 17 Apr 2019 15:18:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGq4Y-0000CP-TZ for qemu-devel@nongnu.org; Wed, 17 Apr 2019 15:18:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hGq4V-0008Q9-5d for qemu-devel@nongnu.org; Wed, 17 Apr 2019 15:18:17 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 41EBD307EA93 for ; Wed, 17 Apr 2019 19:18:10 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-116.ams2.redhat.com [10.36.116.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0982C1001E8D; Wed, 17 Apr 2019 19:18:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9B336113292F; Wed, 17 Apr 2019 21:18:05 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 17 Apr 2019 21:18:01 +0200 Message-Id: <20190417191805.28198-14-armbru@redhat.com> In-Reply-To: <20190417191805.28198-1-armbru@redhat.com> References: <20190417191805.28198-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 17 Apr 2019 19:18:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 13/17] qemu-print: New qemu_fprintf(), qemu_vfprintf() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Code that doesn't want to know about current monitor vs. stdout vs. stderr takes an fprintf_function callback and a FILE * argument to pass to it. Actual arguments are either fprintf() and stdout or stderr, or monitor_fprintf() and the current monitor cast to FILE *. monitor_fprintf() casts it right back, and is otherwise identical to monitor_printf(). The type-punning is ugly. New qemu_fprintf() and qemu_vprintf() address this need without type punning: they are like fprintf() and vfprintf(), except they print to the current monitor when passed a null FILE *. The next commits will put them to use. Signed-off-by: Markus Armbruster Reviewed-by: Dr. David Alan Gilbert --- include/qemu/qemu-print.h | 4 ++++ util/qemu-print.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/qemu/qemu-print.h b/include/qemu/qemu-print.h index 8fed32bf42..40b596262f 100644 --- a/include/qemu/qemu-print.h +++ b/include/qemu/qemu-print.h @@ -16,4 +16,8 @@ int qemu_vprintf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); int qemu_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2); =20 +int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap) + GCC_FMT_ATTR(2, 0); +int qemu_fprintf(FILE *stream, const char *fmt, ...) GCC_FMT_ATTR(2, 3); + #endif diff --git a/util/qemu-print.c b/util/qemu-print.c index 86f9417af8..e79d6b8396 100644 --- a/util/qemu-print.c +++ b/util/qemu-print.c @@ -40,3 +40,30 @@ int qemu_printf(const char *fmt, ...) va_end(ap); return ret; } + +/* + * Print like vfprintf() + * Print to @stream if non-null, else to current monitor. + */ +int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap) +{ + if (!stream) { + return monitor_vprintf(cur_mon, fmt, ap); + } + return vfprintf(stream, fmt, ap); +} + +/* + * Print like fprintf(). + * Print to @stream if non-null, else to current monitor. + */ +int qemu_fprintf(FILE *stream, const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret =3D qemu_vfprintf(stream, fmt, ap); + va_end(ap); + return ret; +} --=20 2.17.2