summaryrefslogtreecommitdiff
path: root/src/util/debug.c
diff options
context:
space:
mode:
authorRob Clark <robclark@freedesktop.org>2015-11-18 16:43:31 -0500
committerRob Clark <robclark@freedesktop.org>2015-11-24 10:02:55 -0500
commitd278e31459374feb18edd97d5adaacccc08f978a (patch)
tree39a401065cc3701c7abcd8ae0eeedf7cdd6d8ebd /src/util/debug.c
parentd3e2c48dfa669899484159cf723d8da574996f65 (diff)
downloadmesa-d278e31459374feb18edd97d5adaacccc08f978a.tar.gz
mesa-d278e31459374feb18edd97d5adaacccc08f978a.tar.bz2
mesa-d278e31459374feb18edd97d5adaacccc08f978a.zip
util: move brw_env_var_as_boolean() to util
Kind of a handy function. And I'll want it available outside of i965 for common nir-pass helpers. Signed-off-by: Rob Clark <robclark@freedesktop.org> Reviewed-by: Nicolai Hähnle <nhaehnle@gmail.com>
Diffstat (limited to 'src/util/debug.c')
-rw-r--r--src/util/debug.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/util/debug.c b/src/util/debug.c
index 3729ce85670..98b1853325d 100644
--- a/src/util/debug.c
+++ b/src/util/debug.c
@@ -51,3 +51,28 @@ parse_debug_string(const char *debug,
return flag;
}
+
+/**
+ * Reads an environment variable and interprets its value as a boolean.
+ *
+ * Recognizes 0/false/no and 1/true/yes. Other values result in the default value.
+ */
+bool
+env_var_as_boolean(const char *var_name, bool default_value)
+{
+ const char *str = getenv(var_name);
+ if (str == NULL)
+ return default_value;
+
+ if (strcmp(str, "1") == 0 ||
+ strcasecmp(str, "true") == 0 ||
+ strcasecmp(str, "yes") == 0) {
+ return true;
+ } else if (strcmp(str, "0") == 0 ||
+ strcasecmp(str, "false") == 0 ||
+ strcasecmp(str, "no") == 0) {
+ return false;
+ } else {
+ return default_value;
+ }
+}