aboutsummaryrefslogtreecommitdiff
path: root/util/envlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/envlist.c')
-rw-r--r--util/envlist.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/util/envlist.c b/util/envlist.c
index ebc06cf0f3..099a544a41 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;
}
/*