Patchwork [3/8] fw_cfg: New fw_cfg_add_string()

login
register
mail settings
Submitter Markus Armbruster
Date Jan. 16, 2013, 1:50 p.m.
Message ID <1358344229-18006-4-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/212517/
State New
Headers show

Comments

Markus Armbruster - Jan. 16, 2013, 1:50 p.m.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/fw_cfg.c | 7 +++++++
 hw/fw_cfg.h | 1 +
 2 files changed, 8 insertions(+)

Patch

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 0361f68..3d6dd5f 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -385,6 +385,13 @@  void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, uint8_t *data, uint32_t len)
     s->entries[arch][key].len = len;
 }
 
+void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value)
+{
+    size_t sz = strlen(value) + 1;
+
+    return fw_cfg_add_bytes(s, key, (uint8_t *)g_memdup(value, sz), sz);
+}
+
 void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value)
 {
     uint16_t *copy;
diff --git a/hw/fw_cfg.h b/hw/fw_cfg.h
index 7d32f28..c2c57cd 100644
--- a/hw/fw_cfg.h
+++ b/hw/fw_cfg.h
@@ -55,6 +55,7 @@  typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
 
 typedef struct FWCfgState FWCfgState;
 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, uint8_t *data, uint32_t len);
+void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
 void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
 void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
 void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);