diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-02-05 10:35:02 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-02-05 10:35:02 -0500 |
commit | df4dcac273e788fae6f9e964b8954a2729ebcc26 (patch) | |
tree | 7e2256aca5ae88a2597f48989a017c9cf207942a /src | |
parent | 294d25a59141451c710639885a4e572a5b38ebd5 (diff) | |
download | spmc-df4dcac273e788fae6f9e964b8954a2729ebcc26.tar.gz |
Recombine elements of pair[1..N] into a single string
Diffstat (limited to 'src')
-rw-r--r-- | src/environment.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/environment.c b/src/environment.c index 1438e83..b56b8de 100644 --- a/src/environment.c +++ b/src/environment.c @@ -90,18 +90,28 @@ void runtime_export(RuntimeEnv *env, char **keys) { for (size_t i = 0; i < strlist_count(env); i++) { char **pair = split(strlist_item(env, i), "="); + char *key = pair[0]; + char *value = NULL; + + // We split a potentially large string by "=" so: + // Recombine elements pair[1..N] into a single string by "=" + if (pair[1] != NULL) { + value = join(&pair[1], "="); + } + if (keys != NULL) { for (size_t j = 0; keys[j] != NULL; j++) { - if (strcmp(keys[j], pair[0]) == 0) { - sprintf(output, "%s %s=\"%s\"", export_command, pair[0], pair[1] ? pair[1] : ""); + if (strcmp(keys[j], key) == 0) { + sprintf(output, "%s %s=\"%s\"", export_command, key, value ? value : ""); puts(output); } } } else { - sprintf(output, "%s %s=\"%s\"", export_command, pair[0], pair[1] ? pair[1] : ""); + sprintf(output, "%s %s=\"%s\"", export_command, key, value ? value : ""); puts(output); } + free(value); split_free(pair); } } @@ -354,10 +364,10 @@ void runtime_set(RuntimeEnv *env, const char *_key, const char *_value) { char *now = join((char *[]) {key, value, NULL}, "="); if (key_offset < 0) { - strlist_set(env, key_offset, now); + strlist_append(env, now); } else { - strlist_append(env, now); + strlist_set(env, key_offset, now); } free(now); free(key); |