util: add a env getter for versions

This lets us parse a standard major.minor version.

Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7520>
This commit is contained in:
Dave Airlie
2020-11-10 09:56:21 +10:00
parent 7507ce1db4
commit 297ad1bbb3
2 changed files with 27 additions and 0 deletions
+24
View File
@@ -216,6 +216,30 @@ debug_get_num_option(const char *name, long dfault)
return result;
}
void
debug_get_version_option(const char *name, unsigned *major, unsigned *minor)
{
const char *str;
str = os_get_option(name);
if (str) {
unsigned v_maj, v_min;
int n;
n = sscanf(str, "%u.%u", &v_maj, &v_min);
if (n != 2) {
debug_printf("Illegal version specified for %s : %s\n", name, str);
return;
}
*major = v_maj;
*minor = v_min;
}
if (debug_get_option_should_print())
debug_printf("%s: %s = %u.%u\n", __FUNCTION__, name, *major, *minor);
return;
}
static bool
str_has_option(const char *str, const char *name)
+3
View File
@@ -157,6 +157,9 @@ debug_disable_error_message_boxes(void);
long
debug_get_num_option(const char *name, long dfault);
void
debug_get_version_option(const char *name, unsigned *major, unsigned *minor);
#ifdef _MSC_VER
__declspec(noreturn)
#endif