qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCHv5 2/3] blockdev: add a function to parse enum ids fr


From: Peter Lieven
Subject: [Qemu-devel] [PATCHv5 2/3] blockdev: add a function to parse enum ids from strings
Date: Sun, 18 May 2014 00:58:18 +0200

this adds a generic function to recover the enum id of a parameter
given as a string.

Signed-off-by: Peter Lieven <address@hidden>
---
 blockdev.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/blockdev.c b/blockdev.c
index 7810e9f..8358aa2 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -288,6 +288,23 @@ static int parse_block_error_action(const char *buf, bool 
is_read, Error **errp)
     }
 }
 
+static inline int parse_enum_option(const char *lookup[], const char *buf, int 
max,
+                             int def, Error **errp)
+{
+    int i;
+    if (!buf) {
+        return def;
+    }
+    for (i = 0; i < max; i++) {
+        if (!strcmp(buf, lookup[i])) {
+            return i;
+        }
+    }
+    error_setg(errp, "invalid parameter value: %s",
+               buf);
+    return def;
+}
+
 static bool check_throttle_config(ThrottleConfig *cfg, Error **errp)
 {
     if (throttle_conflicting(cfg)) {
-- 
1.7.9.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]