2
0

qemu-print.c 1.4 KB

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