dri/common: Add option to allow exposure of 10 bpc color configs. (v2)
[mesa.git] / src / util / debug.c
index 3729ce85670a41186a2105a38106f1b05a23301e..98b1853325d415e73012d2a19fa8db4b1b0660d9 100644 (file)
@@ -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;
+   }
+}