2
0

qemu-print.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include "qemu/osdep.h"
  13. #include "monitor/monitor.h"
  14. #include "qemu/qemu-print.h"
  15. /*
  16. * Print like vprintf().
  17. * Print to current monitor if we have one, else to stdout.
  18. */
  19. int qemu_vprintf(const char *fmt, va_list ap)
  20. {
  21. if (cur_mon) {
  22. return monitor_vprintf(cur_mon, fmt, ap);
  23. }
  24. return vprintf(fmt, ap);
  25. }
  26. /*
  27. * Print like printf().
  28. * Print to current monitor if we have one, else to stdout.
  29. */
  30. int qemu_printf(const char *fmt, ...)
  31. {
  32. va_list ap;
  33. int ret;
  34. va_start(ap, fmt);
  35. ret = qemu_vprintf(fmt, ap);
  36. va_end(ap);
  37. return ret;
  38. }
  39. /*
  40. * Print like vfprintf()
  41. * Print to @stream if non-null, else to current monitor.
  42. */
  43. int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap)
  44. {
  45. if (!stream) {
  46. return monitor_vprintf(cur_mon, fmt, ap);
  47. }
  48. return vfprintf(stream, fmt, ap);
  49. }
  50. /*
  51. * Print like fprintf().
  52. * Print to @stream if non-null, else to current monitor.
  53. */
  54. int qemu_fprintf(FILE *stream, const char *fmt, ...)
  55. {
  56. va_list ap;
  57. int ret;
  58. va_start(ap, fmt);
  59. ret = qemu_vfprintf(stream, fmt, ap);
  60. va_end(ap);
  61. return ret;
  62. }