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 DCEA2138454 for ; Fri, 11 Sep 2015 07:53:59 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5770821C042; Fri, 11 Sep 2015 07:53:35 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D794321C03F for ; Fri, 11 Sep 2015 07:53:34 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 287F9340AB6 for ; Fri, 11 Sep 2015 07:53:29 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id D64091F4 for ; Fri, 11 Sep 2015 07:53:27 +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: <1361595524.2469bbf7607b7544d5df4b0645a0798a226bb5d6.vapier@gentoo> Subject: [gentoo-commits] proj/sandbox:master commit in: libsbutil/ X-VCS-Repository: proj/sandbox X-VCS-Files: libsbutil/environment.c libsbutil/sbutil.h X-VCS-Directories: libsbutil/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 2469bbf7607b7544d5df4b0645a0798a226bb5d6 X-VCS-Branch: master Date: Fri, 11 Sep 2015 07:53:27 +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: cc0320c8-53ad-4726-b060-ac9269c8accd X-Archives-Hash: 5ef6dbee056d718ce7944186d0052cc0 commit: 2469bbf7607b7544d5df4b0645a0798a226bb5d6 Author: Mike Frysinger gentoo org> AuthorDate: Sat Feb 23 04:58:44 2013 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Sat Feb 23 04:58:44 2013 +0000 URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=2469bbf7 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 gentoo.org> libsbutil/environment.c | 26 +++++++++++++++++++------- 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] == '=';