fix local-dynamic model TLS on mips and powerpc
[musl.git] / src / env / unsetenv.c
blob356933546a31a41ad859c3bc08709aa76a5a2644
1 #include <stdlib.h>
2 #include <string.h>
3 #include <errno.h>
5 extern char **__environ;
6 extern char **__env_map;
8 int unsetenv(const char *name)
10 int i, j;
11 size_t l = strlen(name);
13 if (!*name || strchr(name, '=')) {
14 errno = EINVAL;
15 return -1;
17 again:
18 for (i=0; __environ[i] && (memcmp(name, __environ[i], l) || __environ[i][l] != '='); i++);
19 if (__environ[i]) {
20 if (__env_map) {
21 for (j=0; __env_map[j] && __env_map[j] != __environ[i]; j++);
22 free (__env_map[j]);
23 for (; __env_map[j]; j++)
24 __env_map[j] = __env_map[j+1];
26 for (; __environ[i]; i++)
27 __environ[i] = __environ[i+1];
28 goto again;
30 return 0;