[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 02/10] utils: drop strtok_r from envlist_parse
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH 02/10] utils: drop strtok_r from envlist_parse |
Date: |
Tue, 17 Feb 2015 16:40:18 -0600 |
From: Olga Krishtal <address@hidden>
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 <address@hidden>
Signed-off-by: Denis V. Lunev <address@hidden>
CC: Eric Blake <address@hidden>
CC: Michael Roth <address@hidden>
Signed-off-by: Michael Roth <address@hidden>
---
include/sysemu/os-win32.h | 1 -
util/envlist.c | 32 ++++++++++++++++----------------
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index af3fbc4..9cc9e08 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -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) {}
diff --git a/util/envlist.c b/util/envlist.c
index ebc06cf..099a544 100644
--- a/util/envlist.c
+++ b/util/envlist.c
@@ -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;
}
/*
--
1.9.1
- [Qemu-devel] [PULL v2 00/10] Fixes and new commands for QEMU Guest Agent, Michael Roth, 2015/02/17
- [Qemu-devel] [PATCH 09/10] qga: add memory block command that unsupported, Michael Roth, 2015/02/17
- [Qemu-devel] [PATCH 02/10] utils: drop strtok_r from envlist_parse,
Michael Roth <=
- [Qemu-devel] [PATCH 01/10] qga: add guest-set-user-password command, Michael Roth, 2015/02/17
- [Qemu-devel] [PATCH 10/10] qemu-ga-win: Fail loudly on bare 'set-time', Michael Roth, 2015/02/17
- [Qemu-devel] [PATCH 05/10] qga: introduce three guest memory block commmands with stubs, Michael Roth, 2015/02/17
- [Qemu-devel] [PATCH 04/10] qga: implement file commands for Windows guest, Michael Roth, 2015/02/17
- [Qemu-devel] [PATCH 06/10] qga: implement qmp_guest_get_memory_blocks() for Linux with sysfs, Michael Roth, 2015/02/17
- [Qemu-devel] [PATCH 08/10] qga: implement qmp_guest_get_memory_block_info() for Linux with sysfs, Michael Roth, 2015/02/17
- [Qemu-devel] [PATCH 03/10] guest agent: guest-file-open: refactoring, Michael Roth, 2015/02/17
- [Qemu-devel] [PATCH 07/10] qga: implement qmp_guest_set_memory_blocks() for Linux with sysfs, Michael Roth, 2015/02/17
- Re: [Qemu-devel] [PULL v2 00/10] Fixes and new commands for QEMU Guest Agent, Peter Maydell, 2015/02/25