2
0

9p-marshal.c 872 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * 9p backend
  3. *
  4. * Copyright IBM, Corp. 2010
  5. *
  6. * Authors:
  7. * Anthony Liguori <aliguori@us.ibm.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2. See
  10. * the COPYING file in the top-level directory.
  11. *
  12. */
  13. #include "qemu/osdep.h"
  14. #include <glib/gprintf.h>
  15. #include <dirent.h>
  16. #include <utime.h>
  17. #include "9p-marshal.h"
  18. P9ARRAY_DEFINE_TYPE(V9fsString, v9fs_string_free);
  19. void v9fs_string_free(V9fsString *str)
  20. {
  21. g_free(str->data);
  22. str->data = NULL;
  23. str->size = 0;
  24. }
  25. void G_GNUC_PRINTF(2, 3)
  26. v9fs_string_sprintf(V9fsString *str, const char *fmt, ...)
  27. {
  28. va_list ap;
  29. v9fs_string_free(str);
  30. va_start(ap, fmt);
  31. str->size = g_vasprintf(&str->data, fmt, ap);
  32. va_end(ap);
  33. }
  34. void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs)
  35. {
  36. v9fs_string_free(lhs);
  37. v9fs_string_sprintf(lhs, "%s", rhs->data);
  38. }