diff options
Diffstat (limited to 'libsbutil')
-rw-r--r-- | libsbutil/environment.c | 26 | ||||
-rw-r--r-- | libsbutil/sbutil.h | 2 |
2 files changed, 21 insertions, 7 deletions
diff --git a/libsbutil/environment.c b/libsbutil/environment.c index b24189f..70fdb72 100644 --- a/libsbutil/environment.c +++ b/libsbutil/environment.c @@ -10,15 +10,17 @@ #include "headers.h" #include "sbutil.h" -static bool env_is_in(const char *env, const char *values[]) +static bool env_is_in(const char *env, const char *values[], bool *set) { size_t i = 0; const char *val; if (unlikely(!env)) - return false; + return (*set = false); + val = getenv(env); - if (unlikely(!val)) + *set = (val != NULL); + if (unlikely(!*set)) return false; while (values[i]) @@ -28,18 +30,28 @@ static bool env_is_in(const char *env, const char *values[]) return false; } -bool is_env_on(const char *env) +bool is_env_set_on(const char *env, bool *set) { static const char *values[] = { "1", "true", "yes", NULL, }; - return env_is_in(env, values); + return env_is_in(env, values, set); +} +bool is_env_on(const char *env) +{ + bool set; + return is_env_set_on(env, &set); } -bool is_env_off(const char *env) +bool is_env_set_off(const char *env, bool *set) { static const char *values[] = { "0", "false", "no", NULL, }; - return env_is_in(env, values); + return env_is_in(env, values, set); +} +bool is_env_off(const char *env) +{ + bool set; + return is_env_set_off(env, &set); } diff --git a/libsbutil/sbutil.h b/libsbutil/sbutil.h index 993d7ad..02b88cb 100644 --- a/libsbutil/sbutil.h +++ b/libsbutil/sbutil.h @@ -75,6 +75,8 @@ void get_sandbox_message_path(char *path); int get_tmp_dir(char *path); bool is_env_on(const char *); bool is_env_off(const char *); +bool is_env_set_on(const char *, bool *); +bool is_env_set_off(const char *, bool *); static inline bool is_env_var(const char *env, const char *var, size_t vlen) { return !strncmp(env, var, vlen) && env[vlen] == '='; |