diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2009-10-12 17:15:47 +0530 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-10-21 13:35:37 -0500 |
commit | 59419663a139d09018fdd5f59646ce608abd46fc (patch) | |
tree | 25b1e8bf0e9e2f88cd6b5a48ff1efd099961ef20 /hw/qdev-properties.c | |
parent | 6cfa64de908d67fb6f6b6e3ae4888dd863f69e44 (diff) | |
download | qemu-59419663a139d09018fdd5f59646ce608abd46fc.tar.gz qemu-59419663a139d09018fdd5f59646ce608abd46fc.tar.bz2 qemu-59419663a139d09018fdd5f59646ce608abd46fc.zip |
qdev: add string property.
Patchworks-ID: 35755
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/qdev-properties.c')
-rw-r--r-- | hw/qdev-properties.c | 28 |
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) |