env-util: minor modernization

This commit is contained in:
Mike Yuan
2024-02-13 12:59:00 +08:00
parent 52bcc872b5
commit 9128fd553c
3 changed files with 10 additions and 14 deletions

View File

@@ -310,19 +310,17 @@ char **strv_env_delete(char **x, size_t n_lists, ...) {
return TAKE_PTR(t);
}
char **strv_env_unset(char **l, const char *p) {
char **f, **t;
char** strv_env_unset(char **l, const char *p) {
assert(p);
if (!l)
return NULL;
assert(p);
/* Drops every occurrence of the env var setting p in the
* string list. Edits in-place. */
char **f, **t;
for (f = t = l; *f; f++) {
if (env_match(*f, p)) {
free(*f);
continue;
@@ -335,14 +333,13 @@ char **strv_env_unset(char **l, const char *p) {
return l;
}
char **strv_env_unset_many(char **l, ...) {
char **f, **t;
char** strv_env_unset_many_internal(char **l, ...) {
if (!l)
return NULL;
/* Like strv_env_unset() but applies many at once. Edits in-place. */
char **f, **t;
for (f = t = l; *f; f++) {
bool found = false;
const char *p;
@@ -350,12 +347,11 @@ char **strv_env_unset_many(char **l, ...) {
va_start(ap, l);
while ((p = va_arg(ap, const char*))) {
while ((p = va_arg(ap, const char*)))
if (env_match(*f, p)) {
found = true;
break;
}
}
va_end(ap);

View File

@@ -43,8 +43,9 @@ char** _strv_env_merge(char **first, ...);
#define strv_env_merge(first, ...) _strv_env_merge(first, __VA_ARGS__, POINTER_MAX)
char **strv_env_delete(char **x, size_t n_lists, ...); /* New copy */
char **strv_env_unset(char **l, const char *p); /* In place ... */
char **strv_env_unset_many(char **l, ...) _sentinel_;
char** strv_env_unset(char **l, const char *p); /* In place ... */
char** strv_env_unset_many_internal(char **l, ...) _sentinel_;
#define strv_env_unset_many(l, ...) strv_env_unset_many_internal(l, __VA_ARGS__, NULL)
int strv_env_replace_consume(char ***l, char *p); /* In place ... */
int strv_env_replace_strdup(char ***l, const char *assignment);
int strv_env_replace_strdup_passthrough(char ***l, const char *assignment);

View File

@@ -641,8 +641,7 @@ static char** sanitize_environment(char **l) {
"TRIGGER_TIMER_REALTIME_USEC",
"TRIGGER_UNIT",
"WATCHDOG_PID",
"WATCHDOG_USEC",
NULL);
"WATCHDOG_USEC");
/* Let's order the environment alphabetically, just to make it pretty */
return strv_sort(l);