aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2013-02-22 23:58:44 -0500
committerMike Frysinger <vapier@gentoo.org>2013-02-22 23:58:44 -0500
commit2469bbf7607b7544d5df4b0645a0798a226bb5d6 (patch)
tree948f77815bb6ce1e2c3d0e6b0733cca7600365c1
parentsandbox: pass child signals back up to the parent (diff)
downloadsandbox-2469bbf7607b7544d5df4b0645a0798a226bb5d6.tar.gz
sandbox-2469bbf7607b7544d5df4b0645a0798a226bb5d6.tar.bz2
sandbox-2469bbf7607b7544d5df4b0645a0798a226bb5d6.zip
environ: add set variants to env_is_{on,off}
In some situations, we want to know the tristate of "is on", "is off", and "is set" instead of just lumping the "is not set" case in with "is off". Add some helpers for that. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r--libsbutil/environment.c26
-rw-r--r--libsbutil/sbutil.h2
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] == '=';