diff options
author | Ron Yorston <rmy@pobox.com> | 2022-05-03 21:34:01 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2022-05-03 21:34:01 +0100 |
commit | 386fd4d71956d16b1e649c3b3e14f75e84e40310 (patch) | |
tree | 7b8533755bfccba5725430eba0a74624f51ba0bf | |
parent | 6d87be4d760ceda18d354c6d4c523a9adf50c04b (diff) | |
download | busybox-w32-386fd4d71956d16b1e649c3b3e14f75e84e40310.tar.gz busybox-w32-386fd4d71956d16b1e649c3b3e14f75e84e40310.tar.bz2 busybox-w32-386fd4d71956d16b1e649c3b3e14f75e84e40310.zip |
win32: new code to set empty environment variable
Windows environment variables: a never-ending source of fun.
It seems the recent hack to work around problems in UCRT breaks
the hack to set empty environment variables. The change to the
empty variable isn't reflected in the environment seen by the C
runtime.
Use the WIN32 API to set the empty variable then set a dummy
variable to make the C runtime take notice.
(GitHub issue #250)
-rw-r--r-- | win32/env.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/win32/env.c b/win32/env.c index 4d4e9c8fd..5de581e3d 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, **envp; | 81 | char *s; |
82 | int ret = 0; | 82 | int ret = 0; |
83 | 83 | ||
84 | if ( (s=strchr(env, '=')) == NULL ) { | 84 | if ( (s=strchr(env, '=')) == NULL ) { |
@@ -90,17 +90,13 @@ int mingw_putenv(const char *env) | |||
90 | return _putenv(env); | 90 | return _putenv(env); |
91 | } | 91 | } |
92 | else { | 92 | else { |
93 | /* set empty value by setting a non-empty one then truncating */ | 93 | /* set empty value using WIN32 API*/ |
94 | char *envstr = xasprintf("%s0", env); | 94 | char *name = xstrdup(env); |
95 | ret = _putenv(envstr); | 95 | name[s - env] = '\0'; |
96 | 96 | SetEnvironmentVariable(name, ""); | |
97 | for (envp = environ; *envp; ++envp) { | 97 | free(name); |
98 | if (strcmp(*envp, envstr) == 0) { | 98 | /* set a dummy variable to force CRT housekeeping */ |
99 | (*envp)[s - env + 1] = '\0'; | 99 | _putenv("BB_DUMMY=0"); |
100 | break; | ||
101 | } | ||
102 | } | ||
103 | free(envstr); | ||
104 | } | 100 | } |
105 | 101 | ||
106 | return ret; | 102 | return ret; |