未验证 提交 1c0784c5 编写于 作者: O openharmony_ci 提交者: Gitee

!904 Optimize getenv performance

Merge pull request !904 from haotuo/getenv_optimization
......@@ -2183,6 +2183,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 = [
......
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册