aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2015-07-03 14:12:47 +0100
committerRon Yorston <rmy@pobox.com>2015-07-03 14:12:47 +0100
commit9fc98788e4fb1ea1f330d44c8b2019b3fe6444f7 (patch)
tree7620816f022d765923bbd678dcc9aa968cc7f009 /win32
parent171bc72f6a8f996376ca02e44edd56409b27a927 (diff)
downloadbusybox-w32-9fc98788e4fb1ea1f330d44c8b2019b3fe6444f7.tar.gz
busybox-w32-9fc98788e4fb1ea1f330d44c8b2019b3fe6444f7.tar.bz2
busybox-w32-9fc98788e4fb1ea1f330d44c8b2019b3fe6444f7.zip
Allow different ways to manipulate environment for XP vs 64-bit
Commit fa147bd 'Use putenv to implement unsetenv/clearenv' allowed BusyBox to run on ReactOS but broke it on Windows XP so it was reverted. It turns out that the same change is required on 64-bit Windows. Reinstate the 'safe' environment manipulation code but make it a configuration option. Add a config file for 64-bit Windows that does the right thing.
Diffstat (limited to 'win32')
-rw-r--r--win32/env.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/win32/env.c b/win32/env.c
index f8d231a8f..48b86c555 100644
--- a/win32/env.c
+++ b/win32/env.c
@@ -104,12 +104,70 @@ char **env_setenv(char **env, const char *name)
104 else { 104 else {
105 for (; env[i]; i++) 105 for (; env[i]; i++)
106 env[i] = env[i+1]; 106 env[i] = env[i+1];
107#if !ENABLE_SAFE_ENV
107 SetEnvironmentVariable(name, NULL); 108 SetEnvironmentVariable(name, NULL);
109#endif
108 } 110 }
109 } 111 }
110 return env; 112 return env;
111} 113}
112 114
115#if ENABLE_SAFE_ENV
116/*
117 * Removing an environment variable with WIN32 putenv requires an argument
118 * like "NAME="; glibc omits the '='. The implementations of unsetenv and
119 * clearenv allow for this.
120 *
121 * It isn't possible to create an environment variable with an empty value
122 * using WIN32 putenv.
123 */
124#undef putenv
125int unsetenv(const char *env)
126{
127 char *name;
128 int ret;
129
130 name = xmalloc(strlen(env)+2);
131 strcat(strcpy(name, env), "=");
132 ret = putenv(name);
133 free(name);
134
135 return ret;
136}
137
138int clearenv(void)
139{
140 char *name, *s;
141
142 while ( environ && *environ ) {
143 if ( (s=strchr(*environ, '=')) != NULL ) {
144 name = xstrndup(*environ, s-*environ+1);
145 putenv(name);
146 free(name);
147 }
148 else {
149 return -1;
150 }
151 }
152 return 0;
153}
154
155int mingw_putenv(const char *env)
156{
157 char *s;
158
159 if ( (s=strchr(env, '=')) == NULL ) {
160 return unsetenv(env);
161 }
162
163 if ( s[1] != '\0' ) {
164 return putenv(env);
165 }
166
167 /* can't set empty value */
168 return 0;
169}
170#else
113void unsetenv(const char *env) 171void unsetenv(const char *env)
114{ 172{
115 env_setenv(environ, env); 173 env_setenv(environ, env);
@@ -128,3 +186,4 @@ int clearenv(void)
128 environ = NULL; 186 environ = NULL;
129 return 0; 187 return 0;
130} 188}
189#endif