util: Add new function os_get_option_internal to improve os_get_option*
This is for take care of GetEnvironmentVariableA/getenv/secure_getenv/os_get_android_option
consistently across windows/posix/android
And also secure_getenv should not directly used in mesa, remove it from u_debug.h
os_get_option_secure is using getenv for windows before, that also pull the drawback of getenv, so convert it also
using GetEnvironmentVariableA on windows instead.
This is done the same as commit bed69133cd for os_get_option_secure
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Acked-by: Antonio Ospite <antonio.ospite@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38128>
This commit is contained in:
@@ -200,20 +200,29 @@ os_get_android_option(const char *name)
|
||||
* 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 const char *
|
||||
os_get_option_internal(const char *name, UNUSED bool use_secure_getenv)
|
||||
{
|
||||
static thread_local char value[_MAX_ENV];
|
||||
DWORD size = GetEnvironmentVariableA(name, value, _MAX_ENV);
|
||||
return (size > 0 && size < _MAX_ENV) ? value : NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
#else /* !DETECT_OS_WINDOWS */
|
||||
|
||||
const char *
|
||||
os_get_option(const char *name)
|
||||
static const char *
|
||||
os_get_option_internal(const char *name, bool use_secure_getenv)
|
||||
{
|
||||
const char *opt = getenv(name);
|
||||
const char *opt;
|
||||
if (use_secure_getenv) {
|
||||
#ifdef HAVE_SECURE_GETENV
|
||||
opt = secure_getenv(name);
|
||||
#else
|
||||
opt = getenv(name);
|
||||
#endif
|
||||
} else {
|
||||
opt = getenv(name);
|
||||
}
|
||||
#if DETECT_OS_ANDROID
|
||||
if (!opt) {
|
||||
opt = os_get_android_option(name);
|
||||
@@ -222,18 +231,18 @@ os_get_option(const char *name)
|
||||
return opt;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* DETECT_OS_WINDOWS */
|
||||
|
||||
const char *
|
||||
os_get_option(const char *name)
|
||||
{
|
||||
return os_get_option_internal(name, false);
|
||||
}
|
||||
|
||||
const char *
|
||||
os_get_option_secure(const char *name)
|
||||
{
|
||||
const char *opt = secure_getenv(name);
|
||||
#if DETECT_OS_ANDROID
|
||||
if (!opt) {
|
||||
opt = os_get_android_option(name);
|
||||
}
|
||||
#endif
|
||||
return opt;
|
||||
return os_get_option_internal(name, true);
|
||||
}
|
||||
|
||||
static struct hash_table *options_tbl;
|
||||
|
||||
@@ -409,13 +409,6 @@ __normal_user(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef HAVE_SECURE_GETENV
|
||||
static inline char *secure_getenv(const char *name)
|
||||
{
|
||||
return getenv(name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define DEBUG_GET_ONCE_BOOL_OPTION(sufix, name, dfault) \
|
||||
static bool \
|
||||
debug_get_option_ ## sufix (void) \
|
||||
|
||||
Reference in New Issue
Block a user