__wasi_sock_shutdown
__wasilibc_access
__wasilibc_cwd
+__wasilibc_deinitialize_environ
__wasilibc_ensure_environ
__wasilibc_environ
__wasilibc_environ
__wasilibc_link
__wasilibc_link_newat
__wasilibc_link_oldat
+__wasilibc_maybe_reinitialize_environ_eagerly
+__wasilibc_maybe_reinitialize_environ_eagerly
__wasilibc_nocwd___wasilibc_rmdirat
__wasilibc_nocwd___wasilibc_unlinkat
__wasilibc_nocwd_faccessat
#include <stddef.h>
#include_next <stdlib.h>
+
+int clearenv(void);
#ifndef __wasi_libc_environ_h
#define __wasi_libc_environ_h
+/// This header file is a WASI-libc-specific interface, and is not needed by
+/// most programs. Most programs should just use the standard `getenv` and
+/// related APIs, which take care of all of the details automatically.
+
#ifdef __cplusplus
extern "C" {
#endif
/// If `__wasilibc_initialize_environ` has not yet been called, call it.
void __wasilibc_ensure_environ(void);
+/// De-initialize the global environment variable state, so that subsequent
+/// calls to `__wasilibc_ensure_environ` call `__wasilibc_initialize_environ`.
+void __wasilibc_deinitialize_environ(void);
+
+/// Call `__wasilibc_initialize_environ` only if `environ` and `_environ` are
+/// referenced in the program.
+void __wasilibc_maybe_reinitialize_environ_eagerly(void);
+
#ifdef __cplusplus
}
#endif
software:
_Exit(EX_SOFTWARE);
}
+
+// See the comments in libc-environ.h.
+void __wasilibc_deinitialize_environ(void) {
+ if (__wasilibc_environ != (char **)-1) {
+ // Let libc-top-half clear the old environment-variable strings.
+ clearenv();
+ // Set the pointer to the special init value.
+ __wasilibc_environ = (char **)-1;
+ }
+}
+
+// See the comments in libc-environ.h.
+__attribute__((weak))
+void __wasilibc_maybe_reinitialize_environ_eagerly(void) {
+ // This version does nothing. It may be overridden by a version which does
+ // something if `environ` is used.
+}
static void __wasilibc_initialize_environ_eagerly(void) {
__wasilibc_initialize_environ();
}
+
+// See the comments in libc-environ.h.
+void __wasilibc_maybe_reinitialize_environ_eagerly(void) {
+ // This translation unit is linked in if `environ` is used, meaning we need
+ // to eagerly reinitialize the environment variables.
+ __wasilibc_initialize_environ();
+}