diff options
author | Ron Yorston <rmy@pobox.com> | 2014-12-18 10:08:26 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2014-12-18 10:08:26 +0000 |
commit | 067f2e7eaf36deac1175eaf24eeb118adcd37179 (patch) | |
tree | d46f16becc3f0d731dbe7cbfe55ccec29e2c674d /win32 | |
parent | 425eb69dfc56ee2e1a85cdd2ccab8c40121edf59 (diff) | |
download | busybox-w32-067f2e7eaf36deac1175eaf24eeb118adcd37179.tar.gz busybox-w32-067f2e7eaf36deac1175eaf24eeb118adcd37179.tar.bz2 busybox-w32-067f2e7eaf36deac1175eaf24eeb118adcd37179.zip |
Revert "Use putenv to implement unsetenv/clearenv"
This reverts commit fa147bd7ecb086f4fb9a4afea16b946693a822ce.
Diffstat (limited to 'win32')
-rw-r--r-- | win32/env.c | 57 |
1 files changed, 11 insertions, 46 deletions
diff --git a/win32/env.c b/win32/env.c index eb2e1f004..f8d231a8f 100644 --- a/win32/env.c +++ b/win32/env.c | |||
@@ -104,62 +104,27 @@ 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 | SetEnvironmentVariable(name, NULL); | ||
107 | } | 108 | } |
108 | } | 109 | } |
109 | return env; | 110 | return env; |
110 | } | 111 | } |
111 | 112 | ||
112 | /* | 113 | void unsetenv(const char *env) |
113 | * Removing an environment variable with WIN32 putenv requires an argument | ||
114 | * like "NAME="; glibc omits the '='. The implementations of unsetenv and | ||
115 | * clearenv allow for this. | ||
116 | * | ||
117 | * It isn't possible to create an environment variable with an empty value | ||
118 | * using WIN32 putenv. | ||
119 | */ | ||
120 | #undef putenv | ||
121 | int unsetenv(const char *env) | ||
122 | { | 114 | { |
123 | char *name; | 115 | env_setenv(environ, env); |
124 | int ret; | ||
125 | |||
126 | name = xmalloc(strlen(env)+2); | ||
127 | strcat(strcpy(name, env), "="); | ||
128 | ret = putenv(name); | ||
129 | free(name); | ||
130 | |||
131 | return ret; | ||
132 | } | 116 | } |
133 | 117 | ||
134 | int clearenv(void) | 118 | int clearenv(void) |
135 | { | 119 | { |
136 | char *name, *s; | 120 | char **env = environ; |
137 | 121 | if (!env) | |
138 | while ( environ && *environ ) { | 122 | return 0; |
139 | if ( (s=strchr(*environ, '=')) != NULL ) { | 123 | while (*env) { |
140 | name = xstrndup(*environ, s-*environ+1); | 124 | free(*env); |
141 | putenv(name); | 125 | env++; |
142 | free(name); | ||
143 | } | ||
144 | else { | ||
145 | return -1; | ||
146 | } | ||
147 | } | ||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | int mingw_putenv(const char *env) | ||
152 | { | ||
153 | char *s; | ||
154 | |||
155 | if ( (s=strchr(env, '=')) == NULL ) { | ||
156 | return unsetenv(env); | ||
157 | } | 126 | } |
158 | 127 | free(env); | |
159 | if ( s[1] != '\0' ) { | 128 | environ = NULL; |
160 | return putenv(env); | ||
161 | } | ||
162 | |||
163 | /* can't set empty value */ | ||
164 | return 0; | 129 | return 0; |
165 | } | 130 | } |