]> git.proxmox.com Git - mirror_qemu.git/commitdiff
utils: drop strtok_r from envlist_parse
authorOlga Krishtal <okrishtal@parallels.com>
Fri, 6 Feb 2015 17:59:53 +0000 (20:59 +0300)
committerMichael Roth <mdroth@linux.vnet.ibm.com>
Mon, 16 Feb 2015 22:20:02 +0000 (16:20 -0600)
The problem is that mingw 4.9.1 fails to compile the code with the
following warning:

/mingw/include/string.h:88:9: note: previous declaration of 'strtok_r'
was here
   char *strtok_r(char * __restrict__ _Str,
                  const char * __restrict__ _Delim,
                  char ** __restrict__ __last);
/include/sysemu/os-win32.h:83:7: warning: redundant redeclaration of
   'strtok_r' [-Wredundant-decls]
   char *strtok_r(char *str, const char *delim, char **saveptr);

The problem is that compiles just fine on previous versions of mingw.
Compiler version check here is not a good idea. Though fortunately
strtok_r is used only once in the code and we could simply rewrite
the code without it.

Signed-off-by: Olga Krishtal <okrishtal@parallels.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Eric Blake <eblake@redhat.com>
CC: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
include/sysemu/os-win32.h
util/envlist.c

index af3fbc47d80022b4829a3c101434984761eea5d8..9cc9e081392277afc970655368f7f773ca1d12ef 100644 (file)
@@ -81,7 +81,6 @@ struct tm *gmtime_r(const time_t *timep, struct tm *result);
 #undef localtime_r
 struct tm *localtime_r(const time_t *timep, struct tm *result);
 
-char *strtok_r(char *str, const char *delim, char **saveptr);
 
 static inline void os_setup_signal_handling(void) {}
 static inline void os_daemonize(void) {}
index ebc06cf0f3f1ad4a26e68d61064ebb581b39dc4d..099a544a41b0ebaf816bf86b71f82513104ccfea 100644 (file)
@@ -94,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;
 }
 
 /*