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