]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/sources/environ.c
bc5a078724cddb93194fb2a7965f0ec5e32bd7df
[wasi-libc.git] / libc-bottom-half / sources / environ.c
1 #include <unistd.h>
2 #include <stdlib.h>
3 #include <sysexits.h>
4 #include <wasi/api.h>
5 #include <wasi/libc.h>
6 #include <wasi/libc-environ.h>
7
8 // If the program does use `environ`, it'll get this version of
9 // `__wasilibc_environ`, which is initialized with a constructor function, so
10 // that it's initialized whenever user code might want to access it.
11 char **__wasilibc_environ;
12 extern __typeof(__wasilibc_environ) _environ
13 __attribute__((weak, alias("__wasilibc_environ")));
14 extern __typeof(__wasilibc_environ) environ
15 __attribute__((weak, alias("__wasilibc_environ")));
16
17 // We define this function here in the same source file as
18 // `__wasilibc_environ`, so that this function is called in iff environment
19 // variable support is used.
20 // Concerning the 50 -- levels up to 100 are reserved for the implementation,
21 // so we an arbitrary number in the middle of the range to allow other
22 // reserved things to go before or after.
23 __attribute__((constructor(50)))
24 static void __wasilibc_initialize_environ_eagerly(void) {
25 __wasilibc_initialize_environ();
26 }