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:
Sam Lantinga
2024-09-13 17:00:15 -07:00
parent 16ff7503b7
commit 90e01040c5
49 changed files with 696 additions and 252 deletions

View File

@@ -41,7 +41,7 @@ bool SDL_SYS_OpenURL(const char *url)
pid_t pid2;
const char *args[] = { "xdg-open", url, NULL };
// Clear LD_PRELOAD so Chrome opens correctly when this application is launched by Steam
SDL_unsetenv("LD_PRELOAD");
SDL_unsetenv_unsafe("LD_PRELOAD");
if (posix_spawnp(&pid2, args[0], NULL, NULL, (char **)args, environ) == 0) {
// Child process doesn't wait for possibly-blocking grandchild.
_exit(EXIT_SUCCESS);
@@ -51,7 +51,7 @@ bool SDL_SYS_OpenURL(const char *url)
#else
pid_t pid2;
// Clear LD_PRELOAD so Chrome opens correctly when this application is launched by Steam
SDL_unsetenv("LD_PRELOAD");
SDL_unsetenv_unsafe("LD_PRELOAD");
// Notice this is vfork and not fork!
pid2 = vfork();
if (pid2 == 0) { // Grandchild process will try to launch the url