mirror of
https://git.proxmox.com/git/wasi-libc
synced 2025-07-23 14:58:40 +00:00

* Link `populate_environ` only if we actually need environment variables. This avoids linking in the environment variable initialization code, and the __wasi_environ_sizes_get and __wasi_environ_get imports, in programs that don't use environment variables. This also removes the "___environ" (three underscores) alias symbol, which is only in musl for backwards compatibility. * Switch to //-style comments. * If malloc fails, don't leave `__environ` pointing to an uninitialized buffer. * Fix a memory leak if one malloc succeeds and the other fails. * Use calloc to handle multiplication overflow. This also handles the NULL terminator. * Don't initialize __environ until everything has succeeded. * Avoid leaking in case __wasi_environ_get fails. * Handle overflow in the add too. * Add #include <stdlib.h> for malloc etc. * If the environment is empty, don't allocate any memory.
18 lines
250 B
C
18 lines
250 B
C
#ifndef __wasi_libc_internal_h
|
|
#define __wasi_libc_internal_h
|
|
|
|
#include <wasi/core.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
void __wasilibc_init_preopen(void);
|
|
__wasi_errno_t __wasilibc_populate_environ(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|