diff options
author | 2012-12-26 22:47:11 -0500 | |
---|---|---|
committer | 2013-02-24 23:05:05 -0500 | |
commit | f0dbd58bcb7b20ef681e7635f9d4b580816ad5ef (patch) | |
tree | c64d81ebe89ffb18f9e866f8b4d74769f7ba7623 /libsbutil | |
parent | libsandbox: add some likely/unlikely settings (diff) | |
download | sandbox-f0dbd58bcb7b20ef681e7635f9d4b580816ad5ef.tar.gz sandbox-f0dbd58bcb7b20ef681e7635f9d4b580816ad5ef.tar.bz2 sandbox-f0dbd58bcb7b20ef681e7635f9d4b580816ad5ef.zip |
environ: merge is_env_{on,off} into a single file
Start a centralized place for environment related helper funcs.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libsbutil')
-rw-r--r-- | libsbutil/Makefile.am | 3 | ||||
-rw-r--r-- | libsbutil/environment.c | 45 | ||||
-rw-r--r-- | libsbutil/is_env_off.c | 22 | ||||
-rw-r--r-- | libsbutil/is_env_on.c | 22 |
4 files changed, 46 insertions, 46 deletions
diff --git a/libsbutil/Makefile.am b/libsbutil/Makefile.am index f1fed76..39a5ab6 100644 --- a/libsbutil/Makefile.am +++ b/libsbutil/Makefile.am @@ -18,8 +18,7 @@ libsbutil_la_SOURCES = \ get_sandbox_rc.c \ get_sandbox_log.c \ get_tmp_dir.c \ - is_env_on.c \ - is_env_off.c \ + environment.c \ sb_backtrace.c \ sb_efuncs.c \ sb_gdb.c \ diff --git a/libsbutil/environment.c b/libsbutil/environment.c new file mode 100644 index 0000000..b24189f --- /dev/null +++ b/libsbutil/environment.c @@ -0,0 +1,45 @@ +/* + * environment.c + * + * Environment utility functions. + * + * Copyright 1999-2012 Gentoo Foundation + * Licensed under the GPL-2 + */ + +#include "headers.h" +#include "sbutil.h" + +static bool env_is_in(const char *env, const char *values[]) +{ + size_t i = 0; + const char *val; + + if (unlikely(!env)) + return false; + val = getenv(env); + if (unlikely(!val)) + return false; + + while (values[i]) + if (!strcasecmp(val, values[i++])) + return true; + + return false; +} + +bool is_env_on(const char *env) +{ + static const char *values[] = { + "1", "true", "yes", NULL, + }; + return env_is_in(env, values); +} + +bool is_env_off(const char *env) +{ + static const char *values[] = { + "0", "false", "no", NULL, + }; + return env_is_in(env, values); +} diff --git a/libsbutil/is_env_off.c b/libsbutil/is_env_off.c deleted file mode 100644 index 3536ee7..0000000 --- a/libsbutil/is_env_off.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * is_env_off.c - * - * Util functions. - * - * Copyright 1999-2008 Gentoo Foundation - * Licensed under the GPL-2 - */ - -#include "headers.h" -#include "sbutil.h" - -bool is_env_off (const char *env) -{ - if ((NULL != env) && (NULL != getenv(env)) && - ((0 == strncasecmp(getenv(env), "0", 1)) || - (0 == strncasecmp(getenv(env), "false", 5)) || - (0 == strncasecmp(getenv(env), "no", 2)))) - return true; - - return false; -} diff --git a/libsbutil/is_env_on.c b/libsbutil/is_env_on.c deleted file mode 100644 index 18a8cc0..0000000 --- a/libsbutil/is_env_on.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * is_env_on.c - * - * Util functions. - * - * Copyright 1999-2008 Gentoo Foundation - * Licensed under the GPL-2 - */ - -#include "headers.h" -#include "sbutil.h" - -bool is_env_on (const char *env) -{ - if ((NULL != env) && (NULL != getenv(env)) && - ((0 == strncasecmp(getenv(env), "1", 1)) || - (0 == strncasecmp(getenv(env), "true", 4)) || - (0 == strncasecmp(getenv(env), "yes", 3)))) - return true; - - return false; -} |