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
14 #include "qemu/osdep.h"
15 #include <glib/gprintf.h>
16 #include <dirent.h>
17 #include <utime.h>
18
19 #include "9p-marshal.h"
20
21 P9ARRAY_DEFINE_TYPE(V9fsString, v9fs_string_free);
22
v9fs_string_free(V9fsString * str)23 void v9fs_string_free(V9fsString *str)
24 {
25 g_free(str->data);
26 str->data = NULL;
27 str->size = 0;
28 }
29
v9fs_string_sprintf(V9fsString * str,const char * fmt,...)30 void v9fs_string_sprintf(V9fsString *str, const char *fmt, ...)
31 {
32 va_list ap;
33
34 v9fs_string_free(str);
35
36 va_start(ap, fmt);
37 str->size = g_vasprintf(&str->data, fmt, ap);
38 va_end(ap);
39 }
40
v9fs_string_copy(V9fsString * lhs,V9fsString * rhs)41 void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs)
42 {
43 v9fs_string_free(lhs);
44 v9fs_string_sprintf(lhs, "%s", rhs->data);
45 }
46