aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/env.c57
1 files changed, 46 insertions, 11 deletions
diff --git a/win32/env.c b/win32/env.c
index f8d231a8f..eb2e1f004 100644
--- a/win32/env.c
+++ b/win32/env.c
@@ -104,27 +104,62 @@ 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);
108 } 107 }
109 } 108 }
110 return env; 109 return env;
111} 110}
112 111
113void unsetenv(const char *env) 112/*
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
121int unsetenv(const char *env)
114{ 122{
115 env_setenv(environ, env); 123 char *name;
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;
116} 132}
117 133
118int clearenv(void) 134int clearenv(void)
119{ 135{
120 char **env = environ; 136 char *name, *s;
121 if (!env) 137
122 return 0; 138 while ( environ && *environ ) {
123 while (*env) { 139 if ( (s=strchr(*environ, '=')) != NULL ) {
124 free(*env); 140 name = xstrndup(*environ, s-*environ+1);
125 env++; 141 putenv(name);
142 free(name);
143 }
144 else {
145 return -1;
146 }
126 } 147 }
127 free(env); 148 return 0;
128 environ = NULL; 149}
150
151int mingw_putenv(const char *env)
152{
153 char *s;
154
155 if ( (s=strchr(env, '=')) == NULL ) {
156 return unsetenv(env);
157 }
158
159 if ( s[1] != '\0' ) {
160 return putenv(env);
161 }
162
163 /* can't set empty value */
129 return 0; 164 return 0;
130} 165}