From f0dbd58bcb7b20ef681e7635f9d4b580816ad5ef Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 26 Dec 2012 22:47:11 -0500 Subject: environ: merge is_env_{on,off} into a single file Start a centralized place for environment related helper funcs. Signed-off-by: Mike Frysinger --- libsbutil/Makefile.am | 3 +-- libsbutil/environment.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ libsbutil/is_env_off.c | 22 ---------------------- libsbutil/is_env_on.c | 22 ---------------------- 4 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 libsbutil/environment.c delete mode 100644 libsbutil/is_env_off.c delete mode 100644 libsbutil/is_env_on.c 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; -} -- cgit v1.2.3-65-gdbad