]> git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/env/unsetenv.c
b14c4c929b1f18033e68a480d4500856f33bdaa5
[wasi-libc.git] / libc-top-half / musl / src / env / unsetenv.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include <errno.h>
4 #include <unistd.h>
5
6 static void dummy(char *old, char *new) {}
7 weak_alias(dummy, __env_rm_add);
8
9 int unsetenv(const char *name)
10 {
11 size_t l = __strchrnul(name, '=') - name;
12 if (!l || name[l]) {
13 errno = EINVAL;
14 return -1;
15 }
16 if (__environ) {
17 char **e = __environ, **eo = e;
18 for (; *e; e++)
19 if (!strncmp(name, *e, l) && l[*e] == '=')
20 __env_rm_add(*e, 0);
21 else if (eo != e)
22 *eo++ = *e;
23 else
24 eo++;
25 if (eo != e) *eo = 0;
26 }
27 return 0;
28 }