mirror of
https://github.com/systemd/systemd.git
synced 2024-10-31 16:21:26 +03:00
env-util: add strv_env_pairs_get helper
This commit is contained in:
parent
eb590035b9
commit
42e6a77bc5
@ -455,6 +455,18 @@ char *strv_env_get(char **l, const char *name) {
|
||||
return strv_env_get_n(l, name, strlen(name), 0);
|
||||
}
|
||||
|
||||
char *strv_env_pairs_get(char **l, const char *name) {
|
||||
char **key, **value, *result = NULL;
|
||||
|
||||
assert(name);
|
||||
|
||||
STRV_FOREACH_PAIR(key, value, l)
|
||||
if (streq(*key, name))
|
||||
result = *value;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
char **strv_env_clean_with_callback(char **e, void (*invalid_callback)(const char *p, void *userdata), void *userdata) {
|
||||
char **p, **q;
|
||||
int k = 0;
|
||||
|
@ -50,6 +50,7 @@ int strv_env_assign(char ***l, const char *key, const char *value);
|
||||
|
||||
char *strv_env_get_n(char **l, const char *name, size_t k, unsigned flags) _pure_;
|
||||
char *strv_env_get(char **x, const char *n) _pure_;
|
||||
char *strv_env_pairs_get(char **l, const char *name) _pure_;
|
||||
|
||||
int getenv_bool(const char *p);
|
||||
int getenv_bool_secure(const char *p);
|
||||
|
@ -44,6 +44,17 @@ static void test_strv_env_get(void) {
|
||||
assert_se(streq(strv_env_get(l, "FOUR"), "4"));
|
||||
}
|
||||
|
||||
static void test_strv_env_pairs_get(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
char **l = STRV_MAKE("ONE_OR_TWO", "1", "THREE", "3", "ONE_OR_TWO", "2", "FOUR", "4", "FIVE", "5", "SIX", "FIVE", "SEVEN", "7");
|
||||
|
||||
assert_se(streq(strv_env_pairs_get(l, "ONE_OR_TWO"), "2"));
|
||||
assert_se(streq(strv_env_pairs_get(l, "THREE"), "3"));
|
||||
assert_se(streq(strv_env_pairs_get(l, "FOUR"), "4"));
|
||||
assert_se(streq(strv_env_pairs_get(l, "FIVE"), "5"));
|
||||
}
|
||||
|
||||
static void test_strv_env_unset(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
@ -390,6 +401,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
test_strv_env_delete();
|
||||
test_strv_env_get();
|
||||
test_strv_env_pairs_get();
|
||||
test_strv_env_unset();
|
||||
test_strv_env_merge();
|
||||
test_strv_env_replace_strdup();
|
||||
|
Loading…
Reference in New Issue
Block a user