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>
This commit is contained in:
@@ -103,28 +103,3 @@ brw_process_intel_debug_variable(void)
|
||||
uint64_t intel_debug = parse_debug_string(getenv("INTEL_DEBUG"), debug_control);
|
||||
(void) p_atomic_cmpxchg(&INTEL_DEBUG, 0, intel_debug);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
brw_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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user