aboutsummaryrefslogtreecommitdiff
path: root/hw/qdev-properties.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/qdev-properties.c')
-rw-r--r--hw/qdev-properties.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 5c627fae40..8ca345a9d4 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -193,6 +193,34 @@ PropertyInfo qdev_prop_hex64 = {
.print = print_hex64,
};
+/* --- string --- */
+
+static int parse_string(DeviceState *dev, Property *prop, const char *str)
+{
+ char **ptr = qdev_get_prop_ptr(dev, prop);
+
+ if (*ptr)
+ qemu_free(*ptr);
+ *ptr = qemu_strdup(str);
+ return 0;
+}
+
+static int print_string(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+ char **ptr = qdev_get_prop_ptr(dev, prop);
+ if (!*ptr)
+ return snprintf(dest, len, "<null>");
+ return snprintf(dest, len, "\"%s\"", *ptr);
+}
+
+PropertyInfo qdev_prop_string = {
+ .name = "string",
+ .type = PROP_TYPE_STRING,
+ .size = sizeof(char*),
+ .parse = parse_string,
+ .print = print_string,
+};
+
/* --- drive --- */
static int parse_drive(DeviceState *dev, Property *prop, const char *str)