[Mesa-dev] [PATCH 08/14] util: env_var_as_unsigned() helper

Rob Clark robdclark at gmail.com
Mon Nov 12 15:50:52 UTC 2018


So I can drop env2u() helper from freedreno_util.h and get rid of one
small ir3 dependency on gallium/freedreno

Signed-off-by: Rob Clark <robdclark at gmail.com>
---
 src/util/debug.c | 12 ++++++++++++
 src/util/debug.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/src/util/debug.c b/src/util/debug.c
index 98b1853325d..6142801ef60 100644
--- a/src/util/debug.c
+++ b/src/util/debug.c
@@ -76,3 +76,15 @@ env_var_as_boolean(const char *var_name, bool default_value)
       return default_value;
    }
 }
+
+/**
+ * Reads an environment variable and interprets its value as a unsigned.
+ */
+unsigned
+env_var_as_unsigned(const char *var_name, unsigned default_value)
+{
+   char *str = getenv(var_name);
+   if (str)
+      return strtoul(str, NULL, 0);
+   return default_value;
+}
diff --git a/src/util/debug.h b/src/util/debug.h
index 75ebc2ebffb..2e34ebe3421 100644
--- a/src/util/debug.h
+++ b/src/util/debug.h
@@ -41,6 +41,8 @@ parse_debug_string(const char *debug,
                    const struct debug_control *control);
 bool
 env_var_as_boolean(const char *var_name, bool default_value);
+unsigned
+env_var_as_unsigned(const char *var_name, unsigned default_value);
 
 #ifdef __cplusplus
 } /* extern C */
-- 
2.19.1



More information about the mesa-dev mailing list