Wei Liu | 829dd28 | 2015-11-25 14:38:17 +0000 | [diff] [blame] | 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 | |
Peter Maydell | fbc0412 | 2016-01-26 18:17:10 +0000 | [diff] [blame] | 14 | #include "qemu/osdep.h" |
Wei Liu | 829dd28 | 2015-11-25 14:38:17 +0000 | [diff] [blame] | 15 | #include <glib/gprintf.h> |
Wei Liu | 829dd28 | 2015-11-25 14:38:17 +0000 | [diff] [blame] | 16 | #include <dirent.h> |
Wei Liu | 829dd28 | 2015-11-25 14:38:17 +0000 | [diff] [blame] | 17 | #include <utime.h> |
Wei Liu | 829dd28 | 2015-11-25 14:38:17 +0000 | [diff] [blame] | 18 | |
Wei Liu | 829dd28 | 2015-11-25 14:38:17 +0000 | [diff] [blame] | 19 | #include "9p-marshal.h" |
| 20 | |
Christian Schoenebeck | 42bdeb0 | 2021-10-01 16:27:29 +0200 | [diff] [blame] | 21 | P9ARRAY_DEFINE_TYPE(V9fsString, v9fs_string_free); |
| 22 | |
Wei Liu | 829dd28 | 2015-11-25 14:38:17 +0000 | [diff] [blame] | 23 | void v9fs_string_free(V9fsString *str) |
| 24 | { |
| 25 | g_free(str->data); |
| 26 | str->data = NULL; |
| 27 | str->size = 0; |
| 28 | } |
| 29 | |
Marc-André Lureau | 9edc631 | 2022-02-20 20:39:25 +0400 | [diff] [blame] | 30 | void G_GNUC_PRINTF(2, 3) |
Wei Liu | 829dd28 | 2015-11-25 14:38:17 +0000 | [diff] [blame] | 31 | v9fs_string_sprintf(V9fsString *str, const char *fmt, ...) |
| 32 | { |
| 33 | va_list ap; |
| 34 | |
| 35 | v9fs_string_free(str); |
| 36 | |
| 37 | va_start(ap, fmt); |
| 38 | str->size = g_vasprintf(&str->data, fmt, ap); |
| 39 | va_end(ap); |
| 40 | } |
| 41 | |
| 42 | void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs) |
| 43 | { |
| 44 | v9fs_string_free(lhs); |
| 45 | v9fs_string_sprintf(lhs, "%s", rhs->data); |
| 46 | } |