X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Fenv-util.c;h=b2e45531ab7ec0131e102075bc9b09397dfe0fb1;hp=6a52fb960d0e8df25791b66e6375263b8bc7c353;hb=6db615c17ee7a434f9e0c40d67a1f833d8f3cc9d;hpb=44a6b1b68029833893f6e9cee35aa27a974038f6 diff --git a/src/shared/env-util.c b/src/shared/env-util.c index 6a52fb960..b2e45531a 100644 --- a/src/shared/env-util.c +++ b/src/shared/env-util.c @@ -27,11 +27,10 @@ #include "utf8.h" #include "util.h" #include "env-util.h" +#include "def.h" #define VALID_CHARS_ENV_NAME \ - "0123456789" \ - "abcdefghijklmnopqrstuvwxyz" \ - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ + DIGITS LETTERS \ "_" #ifndef ARG_MAX @@ -311,7 +310,7 @@ char **strv_env_unset(char **l, const char *p) { assert(p); /* Drops every occurrence of the env var setting p in the - * string list. edits in-place. */ + * string list. Edits in-place. */ for (f = t = l; *f; f++) { @@ -327,6 +326,43 @@ char **strv_env_unset(char **l, const char *p) { return l; } +char **strv_env_unset_many(char **l, ...) { + + char **f, **t; + + if (!l) + return NULL; + + /* Like strv_env_unset() but applies many at once. Edits in-place. */ + + for (f = t = l; *f; f++) { + bool found = false; + const char *p; + va_list ap; + + va_start(ap, l); + + while ((p = va_arg(ap, const char*))) { + if (env_match(*f, p)) { + found = true; + break; + } + } + + va_end(ap); + + if (found) { + free(*f); + continue; + } + + *(t++) = *f; + } + + *t = NULL; + return l; +} + char **strv_env_set(char **x, const char *p) { char **k, **r; @@ -406,7 +442,9 @@ char **strv_env_clean_log(char **e, const char *message) { e[k++] = *p; } - e[k] = NULL; + if (e) + e[k] = NULL; + return e; }