mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
win32: Fix environment variables set with pa_{unset,set}_env not taking effect
SetEnvironmentVariable is not visible to getenv. See https://github.com/curl/curl/issues/4774. See https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getenv-wgetenv. Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/546>
This commit is contained in:
parent
ac8e786026
commit
a01cce726f
1 changed files with 18 additions and 2 deletions
|
|
@ -3005,7 +3005,16 @@ void pa_set_env(const char *key, const char *value) {
|
|||
/* This is not thread-safe */
|
||||
|
||||
#ifdef OS_IS_WIN32
|
||||
SetEnvironmentVariable(key, value);
|
||||
int kl = strlen(key);
|
||||
int vl = strlen(value);
|
||||
char *tmp = pa_xmalloc(kl+vl+2);
|
||||
memcpy(tmp, key, kl);
|
||||
memcpy(tmp+kl+1, value, vl);
|
||||
tmp[kl] = '=';
|
||||
tmp[kl+1+vl] = '\0';
|
||||
putenv(tmp);
|
||||
/* Even though it should be safe to free it on Windows, we don't want to
|
||||
* rely on undocumented behaviour. */
|
||||
#else
|
||||
setenv(key, value, 1);
|
||||
#endif
|
||||
|
|
@ -3017,7 +3026,14 @@ void pa_unset_env(const char *key) {
|
|||
/* This is not thread-safe */
|
||||
|
||||
#ifdef OS_IS_WIN32
|
||||
SetEnvironmentVariable(key, NULL);
|
||||
int kl = strlen(key);
|
||||
char *tmp = pa_xmalloc(kl+2);
|
||||
memcpy(tmp, key, kl);
|
||||
tmp[kl] = '=';
|
||||
tmp[kl+1] = '\0';
|
||||
putenv(tmp);
|
||||
/* Even though it should be safe to free it on Windows, we don't want to
|
||||
* rely on undocumented behaviour. */
|
||||
#else
|
||||
unsetenv(key);
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue