| 1 |
#include <stdlib.h> |
| 2 |
#include <string.h> |
| 3 |
#include <unistd.h> |
| 4 |
|
| 5 |
char *getenv(const char *name) |
| 6 |
{ |
| 7 |
#ifdef __wasilibc_unmodified_upstream // Lazy environment variable init. |
| 8 |
#else |
| 9 |
// This specialized header is included within the function body to arranges for |
| 10 |
// the environment variables to be lazily initialized. It redefined `__environ`, |
| 11 |
// so don't remove or reorder it with respect to other code. |
| 12 |
#include "wasi/libc-environ-compat.h" |
| 13 |
#endif |
| 14 |
size_t l = __strchrnul(name, '=') - name; |
| 15 |
if (l && !name[l] && __environ) |
| 16 |
for (char **e = __environ; *e; e++) |
| 17 |
if (!strncmp(name, *e, l) && l[*e] == '=') |
| 18 |
return *e + l+1; |
| 19 |
return 0; |
| 20 |
} |