diff options
| author | Ron Yorston <rmy@pobox.com> | 2022-05-04 14:26:39 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2022-05-04 14:27:32 +0100 |
| commit | 9e535b09a70a1ef7a2260e6d6955f7bbf291a08f (patch) | |
| tree | b07f66df7442bcc119e9b62e113ad4cc1d4aa32e /win32/env.c | |
| parent | 386fd4d71956d16b1e649c3b3e14f75e84e40310 (diff) | |
| download | busybox-w32-9e535b09a70a1ef7a2260e6d6955f7bbf291a08f.tar.gz busybox-w32-9e535b09a70a1ef7a2260e6d6955f7bbf291a08f.tar.bz2 busybox-w32-9e535b09a70a1ef7a2260e6d6955f7bbf291a08f.zip | |
win32: revert changes related to environment variables
Revert the change to mingw_putenv() in the previous commit.
When compiling for MSVCRT (i.e. not for UCRT) revert some of the
changes from commit 5b48ca53b (win32: pass NULL to spawnve, not
environ).
(GitHub issue #250)
Diffstat (limited to 'win32/env.c')
| -rw-r--r-- | win32/env.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/win32/env.c b/win32/env.c index 5de581e3d..4d4e9c8fd 100644 --- a/win32/env.c +++ b/win32/env.c | |||
| @@ -78,7 +78,7 @@ int clearenv(void) | |||
| 78 | 78 | ||
| 79 | int mingw_putenv(const char *env) | 79 | int mingw_putenv(const char *env) |
| 80 | { | 80 | { |
| 81 | char *s; | 81 | char *s, **envp; |
| 82 | int ret = 0; | 82 | int ret = 0; |
| 83 | 83 | ||
| 84 | if ( (s=strchr(env, '=')) == NULL ) { | 84 | if ( (s=strchr(env, '=')) == NULL ) { |
| @@ -90,13 +90,17 @@ int mingw_putenv(const char *env) | |||
| 90 | return _putenv(env); | 90 | return _putenv(env); |
| 91 | } | 91 | } |
| 92 | else { | 92 | else { |
| 93 | /* set empty value using WIN32 API*/ | 93 | /* set empty value by setting a non-empty one then truncating */ |
| 94 | char *name = xstrdup(env); | 94 | char *envstr = xasprintf("%s0", env); |
| 95 | name[s - env] = '\0'; | 95 | ret = _putenv(envstr); |
| 96 | SetEnvironmentVariable(name, ""); | 96 | |
| 97 | free(name); | 97 | for (envp = environ; *envp; ++envp) { |
| 98 | /* set a dummy variable to force CRT housekeeping */ | 98 | if (strcmp(*envp, envstr) == 0) { |
| 99 | _putenv("BB_DUMMY=0"); | 99 | (*envp)[s - env + 1] = '\0'; |
| 100 | break; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | free(envstr); | ||
| 100 | } | 104 | } |
| 101 | 105 | ||
| 102 | return ret; | 106 | return ret; |
