]> git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/env/clearenv.c
Lazy-initialize the environment variables. (#184)
[wasi-libc.git] / libc-top-half / musl / src / env / clearenv.c
1 #define _GNU_SOURCE
2 #include <stdlib.h>
3 #include <unistd.h>
4
5 static void dummy(char *old, char *new) {}
6 weak_alias(dummy, __env_rm_add);
7
8 int clearenv()
9 {
10 #ifdef __wasilibc_unmodified_upstream // Lazy environment variable init.
11 #else
12 // This specialized header is included within the function body to arranges for
13 // the environment variables to be lazily initialized. It redefined `__environ`,
14 // so don't remove or reorder it with respect to other code.
15 #include "wasi/libc-environ-compat.h"
16 #endif
17 char **e = __environ;
18 __environ = 0;
19 if (e) while (*e) __env_rm_add(*e++, 0);
20 return 0;
21 }