From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 80433198005 for ; Mon, 25 Feb 2013 04:08:17 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D4AA6E04ED; Mon, 25 Feb 2013 04:08:16 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id EFE2FE04ED for ; Mon, 25 Feb 2013 04:08:15 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D49E733DD9E for ; Mon, 25 Feb 2013 04:08:14 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 6CDD2E4083 for ; Mon, 25 Feb 2013 04:08:13 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1361765105.f0dbd58bcb7b20ef681e7635f9d4b580816ad5ef.vapier@gentoo> Subject: [gentoo-commits] proj/sandbox:master commit in: libsbutil/ X-VCS-Repository: proj/sandbox X-VCS-Files: libsbutil/Makefile.am libsbutil/environment.c libsbutil/is_env_off.c libsbutil/is_env_on.c X-VCS-Directories: libsbutil/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: f0dbd58bcb7b20ef681e7635f9d4b580816ad5ef X-VCS-Branch: master Date: Mon, 25 Feb 2013 04:08:13 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: ec2648a1-2ac8-40cf-99cc-575906dad97c X-Archives-Hash: d4fa6c17c0942756856bad812c278bab commit: f0dbd58bcb7b20ef681e7635f9d4b580816ad5ef Author: Mike Frysinger gentoo org> AuthorDate: Thu Dec 27 03:47:11 2012 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Mon Feb 25 04:05:05 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/sandbox.git;a=commit;h=f0dbd58b environ: merge is_env_{on,off} into a single file Start a centralized place for environment related helper funcs. Signed-off-by: Mike Frysinger gentoo.org> --- 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(-) 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; -}