mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-05 07:09:32 +00:00
Added thread-safe environment functions
Also marked the existing functions as unsafe, as they can cause crashes if used in multi-threaded applications. As a bonus, since the new functions are hashtable based, hint environment lookups are much faster.
This commit is contained in:
@@ -331,14 +331,14 @@ static char *IBus_GetDBusAddressFilename(void)
|
||||
}
|
||||
|
||||
// Use this environment variable if it exists.
|
||||
addr = SDL_getenv("IBUS_ADDRESS");
|
||||
addr = SDL_GetEnvironmentVariable(SDL_GetEnvironment(), "IBUS_ADDRESS");
|
||||
if (addr && *addr) {
|
||||
return SDL_strdup(addr);
|
||||
}
|
||||
|
||||
/* Otherwise, we have to get the hostname, display, machine id, config dir
|
||||
and look up the address from a filepath using all those bits, eek. */
|
||||
disp_env = SDL_getenv("DISPLAY");
|
||||
disp_env = SDL_GetEnvironmentVariable(SDL_GetEnvironment(), "DISPLAY");
|
||||
|
||||
if (!disp_env || !*disp_env) {
|
||||
display = SDL_strdup(":0.0");
|
||||
@@ -363,7 +363,7 @@ static char *IBus_GetDBusAddressFilename(void)
|
||||
}
|
||||
|
||||
if (!*host) {
|
||||
const char *session = SDL_getenv("XDG_SESSION_TYPE");
|
||||
const char *session = SDL_GetEnvironmentVariable(SDL_GetEnvironment(), "XDG_SESSION_TYPE");
|
||||
if (session && SDL_strcmp(session, "wayland") == 0) {
|
||||
host = "unix-wayland";
|
||||
} else {
|
||||
@@ -373,11 +373,11 @@ static char *IBus_GetDBusAddressFilename(void)
|
||||
|
||||
SDL_memset(config_dir, 0, sizeof(config_dir));
|
||||
|
||||
conf_env = SDL_getenv("XDG_CONFIG_HOME");
|
||||
conf_env = SDL_GetEnvironmentVariable(SDL_GetEnvironment(), "XDG_CONFIG_HOME");
|
||||
if (conf_env && *conf_env) {
|
||||
SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
|
||||
} else {
|
||||
const char *home_env = SDL_getenv("HOME");
|
||||
const char *home_env = SDL_GetEnvironmentVariable(SDL_GetEnvironment(), "HOME");
|
||||
if (!home_env || !*home_env) {
|
||||
SDL_free(display);
|
||||
return NULL;
|
||||
|
||||
@@ -44,8 +44,8 @@ static void InitIME(void)
|
||||
{
|
||||
static bool inited = false;
|
||||
#ifdef HAVE_FCITX
|
||||
const char *im_module = SDL_getenv("SDL_IM_MODULE");
|
||||
const char *xmodifiers = SDL_getenv("XMODIFIERS");
|
||||
const char *im_module = SDL_GetEnvironmentVariable(SDL_GetEnvironment(), "SDL_IM_MODULE");
|
||||
const char *xmodifiers = SDL_GetEnvironmentVariable(SDL_GetEnvironment(), "XMODIFIERS");
|
||||
#endif
|
||||
|
||||
if (inited == true) {
|
||||
|
||||
@@ -33,7 +33,9 @@ SDL_Sandbox SDL_DetectSandbox(void)
|
||||
|
||||
/* For Snap, we check multiple variables because they might be set for
|
||||
* unrelated reasons. This is the same thing WebKitGTK does. */
|
||||
if (SDL_getenv("SNAP") != NULL && SDL_getenv("SNAP_NAME") != NULL && SDL_getenv("SNAP_REVISION") != NULL) {
|
||||
if (SDL_GetEnvironmentVariable(SDL_GetEnvironment(), "SNAP") != NULL &&
|
||||
SDL_GetEnvironmentVariable(SDL_GetEnvironment(), "SNAP_NAME") != NULL &&
|
||||
SDL_GetEnvironmentVariable(SDL_GetEnvironment(), "SNAP_REVISION") != NULL) {
|
||||
return SDL_SANDBOX_SNAP;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user