diff --git a/musl_src.gni b/musl_src.gni index 07b5e05efb69ada715be3a88812bc9fe3425bf88..50d5da0ee520b11aabb20106043fbc176c9b18bf 100644 --- a/musl_src.gni +++ b/musl_src.gni @@ -2180,6 +2180,7 @@ musl_src_porting_file = [ "src/sigchain/sigchain.c", "src/conf/legacy.c", "src/conf/sysconf.c", + "src/env/getenv.c", ] musl_inc_hook_files = [ diff --git a/porting/linux/user/src/env/getenv.c b/porting/linux/user/src/env/getenv.c new file mode 100644 index 0000000000000000000000000000000000000000..d5fa6710a0db4f4575797f5ea708bfe54eb0007c --- /dev/null +++ b/porting/linux/user/src/env/getenv.c @@ -0,0 +1,24 @@ +#include +#include +#include + +char *getenv(const char *name) +{ + if (name == NULL || __environ == NULL) + return 0; + size_t i, l = 0; + const char *np; + char **p, *ep; + for (; *(name + l) && *(name + l) != '='; ++l); + for (p = __environ; (ep = *p) != NULL; ++p) { + for (np = name, i = l; i && *ep; i--) { + if (*ep++ != *np++) { + break; + } + } + if (i == 0 && *ep++ == '=') { + return (ep); + } + } + return 0; +}