xref: /qemu/fsdev/9p-marshal.c (revision 52ea63de)
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 #include <sys/uio.h>
19 
20 #include "9p-marshal.h"
21 
22 void v9fs_string_free(V9fsString *str)
23 {
24     g_free(str->data);
25     str->data = NULL;
26     str->size = 0;
27 }
28 
29 void v9fs_string_null(V9fsString *str)
30 {
31     v9fs_string_free(str);
32 }
33 
34 void GCC_FMT_ATTR(2, 3)
35 v9fs_string_sprintf(V9fsString *str, const char *fmt, ...)
36 {
37     va_list ap;
38 
39     v9fs_string_free(str);
40 
41     va_start(ap, fmt);
42     str->size = g_vasprintf(&str->data, fmt, ap);
43     va_end(ap);
44 }
45 
46 void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs)
47 {
48     v9fs_string_free(lhs);
49     v9fs_string_sprintf(lhs, "%s", rhs->data);
50 }
51