]> Git Repo - qemu.git/blobdiff - util/envlist.c
block: Split out parse_json_protocol()
[qemu.git] / util / envlist.c
index ff99fc44e97329e6bd8f0ea19b7ea26503d62830..099a544a41b0ebaf816bf86b71f82513104ccfea 100644 (file)
@@ -1,9 +1,4 @@
-#include <assert.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
+#include "qemu-common.h"
 #include "qemu/queue.h"
 #include "qemu/envlist.h"
 
@@ -99,30 +94,30 @@ envlist_parse(envlist_t *envlist, const char *env,
 {
        char *tmpenv, *envvar;
        char *envsave = NULL;
-
-       assert(callback != NULL);
+    int ret = 0;
+    assert(callback != NULL);
 
        if ((envlist == NULL) || (env == NULL))
                return (EINVAL);
 
-       /*
-        * We need to make temporary copy of the env string
-        * as strtok_r(3) modifies it while it tokenizes.
-        */
        if ((tmpenv = strdup(env)) == NULL)
                return (errno);
-
-       envvar = strtok_r(tmpenv, ",", &envsave);
-       while (envvar != NULL) {
-               if ((*callback)(envlist, envvar) != 0) {
-                       free(tmpenv);
-                       return (errno);
+    envsave = tmpenv;
+
+    do {
+        envvar = strchr(tmpenv, ',');
+        if (envvar != NULL) {
+            *envvar = '\0';
+        }
+        if ((*callback)(envlist, tmpenv) != 0) {
+            ret = errno;
+            break;
                }
-               envvar = strtok_r(NULL, ",", &envsave);
-       }
+        tmpenv = envvar + 1;
+    } while (envvar != NULL);
 
-       free(tmpenv);
-       return (0);
+    free(envsave);
+    return ret;
 }
 
 /*
This page took 0.02592 seconds and 4 git commands to generate.