9p-marshal.c 819 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. void v9fs_string_free(V9fsString *str)
  19. {
  20. g_free(str->data);
  21. str->data = NULL;
  22. str->size = 0;
  23. }
  24. void GCC_FMT_ATTR(2, 3)
  25. v9fs_string_sprintf(V9fsString *str, const char *fmt, ...)
  26. {
  27. va_list ap;
  28. v9fs_string_free(str);
  29. va_start(ap, fmt);
  30. str->size = g_vasprintf(&str->data, fmt, ap);
  31. va_end(ap);
  32. }
  33. void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs)
  34. {
  35. v9fs_string_free(lhs);
  36. v9fs_string_sprintf(lhs, "%s", rhs->data);
  37. }