goto fail;
}
+ final_env = strv_env_clean(final_env);
+
execve(command->path, final_argv, final_env);
r = EXIT_EXEC;
goto finish;
}
- t = strv_env_set(*env, u);
+ t = strv_append(*env, u);
free(u);
if (!t) {
/* Add the entries of a to *k unless they already exist in *r
* in which case they are overriden instead. This assumes
- * there is enough space in the r */
+ * there is enough space in the r array. */
for (; *a; a++) {
char **j;
char *strv_env_get(char **l, const char *name) {
return strv_env_get_with_length(l, name, strlen(name));
}
+
+char **strv_env_clean(char **l) {
+ char **r, **ret;
+
+ for (r = ret = l; *l; l++) {
+ const char *equal;
+
+ equal = strchr(*l, '=');
+
+ if (equal && equal[1] == 0) {
+ free(*l);
+ continue;
+ }
+
+ *(r++) = *l;
+ }
+
+ *r = NULL;
+
+ return ret;
+}
char *strv_env_get_with_length(char **l, const char *name, size_t k);
char *strv_env_get(char **x, const char *n);
+char **strv_env_clean(char **l);
+
#define STRV_FOREACH(s, l) \
for ((s) = (l); (s) && *(s); (s)++)
NULL
};
- char **i, **r, *t;
+ char **i, **r, *t, **a, **b;
r = replace_env_argv((char**) line, (char**) env);
printf("%s\n", t);
free(t);
+ a = strv_new("FOO=BAR", "WALDO=WALDO", "WALDO=", "PIEP", "SCHLUMPF=SMURF", NULL);
+ b = strv_new("FOO=KKK", "FOO=", "PIEP=", "SCHLUMPF=SMURFF", "NANANANA=YES", NULL);
+
+ r = strv_env_merge(2, a, b);
+ strv_free(a);
+ strv_free(b);
+
+ STRV_FOREACH(i, r)
+ printf("%s\n", *i);
+
+ printf("CLEANED UP:\n");
+
+ r = strv_env_clean(r);
+
+ STRV_FOREACH(i, r)
+ printf("%s\n", *i);
+
+ strv_free(r);
+
return 0;
}