From: Patrick Gaskin Date: Sun, 30 May 2021 19:24:56 +0000 (-0400) Subject: win32: Fix environment variables set with pa_{unset,set}_env not taking effect X-Git-Tag: v14.99.2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a01cce726f175f43ee4b2bb733ad3d54d0de8415;p=platform%2Fupstream%2Fpulseaudio.git 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: --- diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 24736e8..89e37d5 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -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