xref: /qemu/util/qemu-print.c (revision 727385c4)
1 /*
2  * Print to stream or current monitor
3  *
4  * Copyright (C) 2019 Red Hat Inc.
5  *
6  * Authors:
7  *  Markus Armbruster <armbru@redhat.com>,
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10  * See the COPYING file in the top-level directory.
11  */
12 
13 #include "qemu/osdep.h"
14 #include "monitor/monitor.h"
15 #include "qemu/qemu-print.h"
16 
17 /*
18  * Print like vprintf().
19  * Print to current monitor if we have one, else to stdout.
20  */
21 int qemu_vprintf(const char *fmt, va_list ap)
22 {
23     Monitor *cur_mon = monitor_cur();
24     if (cur_mon) {
25         return monitor_vprintf(cur_mon, fmt, ap);
26     }
27     return vprintf(fmt, ap);
28 }
29 
30 /*
31  * Print like printf().
32  * Print to current monitor if we have one, else to stdout.
33  */
34 int qemu_printf(const char *fmt, ...)
35 {
36     va_list ap;
37     int ret;
38 
39     va_start(ap, fmt);
40     ret = qemu_vprintf(fmt, ap);
41     va_end(ap);
42     return ret;
43 }
44 
45 /*
46  * Print like vfprintf()
47  * Print to @stream if non-null, else to current monitor.
48  */
49 int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap)
50 {
51     if (!stream) {
52         return monitor_vprintf(monitor_cur(), fmt, ap);
53     }
54     return vfprintf(stream, fmt, ap);
55 }
56 
57 /*
58  * Print like fprintf().
59  * Print to @stream if non-null, else to current monitor.
60  */
61 int qemu_fprintf(FILE *stream, const char *fmt, ...)
62 {
63     va_list ap;
64     int ret;
65 
66     va_start(ap, fmt);
67     ret = qemu_vfprintf(stream, fmt, ap);
68     va_end(ap);
69     return ret;
70 }
71