From: "Mike Frysinger" <vapier@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/sandbox:master commit in: libsbutil/
Date: Fri, 11 Sep 2015 07:53:27 +0000 (UTC) [thread overview]
Message-ID: <1361595524.2469bbf7607b7544d5df4b0645a0798a226bb5d6.vapier@gentoo> (raw)
commit: 2469bbf7607b7544d5df4b0645a0798a226bb5d6
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 23 04:58:44 2013 +0000
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> 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 <vapier <AT> 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] == '=';
next reply other threads:[~2015-09-11 7:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-11 7:53 Mike Frysinger [this message]
-- strict thread matches above, loose matches on Subject: below --
2023-07-17 13:54 [gentoo-commits] proj/sandbox:master commit in: libsbutil/ Mike Gilbert
2021-11-05 10:25 Mike Frysinger
2021-11-03 21:10 Andreas K. Hüttel
2021-11-03 4:59 Mike Frysinger
2021-10-18 8:48 Mike Frysinger
2016-11-27 18:31 Mike Frysinger
2016-01-18 6:18 Mike Frysinger
2015-12-20 8:41 Mike Frysinger
2015-09-20 8:15 Mike Frysinger
2015-09-11 7:53 Mike Frysinger
2015-09-11 7:53 Mike Frysinger
2013-02-25 4:08 Mike Frysinger
2012-12-24 5:23 Mike Frysinger
2012-12-24 5:19 Mike Frysinger
2012-11-26 10:10 Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1361595524.2469bbf7607b7544d5df4b0645a0798a226bb5d6.vapier@gentoo \
--to=vapier@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox