util: Re-implement getenv for Windows
On Windows, the C runtime maintains an environment variable cache for getenv. But apps and drivers are free to statically link the C runtime, so you might get different environment variable caches between components. Specifically, a test trying to putenv to update the environment won't have its update reflected by the driver if the CRT is statically linked, unless we go to the Win32 API directly. Reviewed-by: Sil Vilerino <sivileri@microsoft.com> Reviewed-by: Yonggang Luo <luoyonggang@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26744>
This commit is contained in:
parent
a0b7ae859f
commit
bed69133cd
1 changed files with 18 additions and 0 deletions
|
|
@ -175,6 +175,22 @@ os_get_android_option(const char *name)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if DETECT_OS_WINDOWS
|
||||
|
||||
/* getenv doesn't necessarily reflect changes to the environment
|
||||
* that have been made during the process lifetime, if either the
|
||||
* setter uses a different CRT (e.g. due to static linking) or the
|
||||
* setter used the Win32 API directly. */
|
||||
const char *
|
||||
os_get_option(const char *name)
|
||||
{
|
||||
static thread_local char value[_MAX_ENV];
|
||||
DWORD size = GetEnvironmentVariableA(name, value, _MAX_ENV);
|
||||
return (size > 0 && size < _MAX_ENV) ? value : NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
const char *
|
||||
os_get_option(const char *name)
|
||||
{
|
||||
|
|
@ -187,6 +203,8 @@ os_get_option(const char *name)
|
|||
return opt;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static struct hash_table *options_tbl;
|
||||
static bool options_tbl_exited = false;
|
||||
static simple_mtx_t options_tbl_mtx = SIMPLE_MTX_INITIALIZER;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue