MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / LLVM_LIBC_FUNCTION

Function LLVM_LIBC_FUNCTION

system/lib/llvm-libc/src/stdlib/getenv.cpp:19–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17namespace LIBC_NAMESPACE_DECL {
18
19LLVM_LIBC_FUNCTION(char *, getenv, (const char *name)) {
20 char **env_ptr = reinterpret_cast<char **>(LIBC_NAMESPACE::app.env_ptr);
21
22 if (name == nullptr || env_ptr == nullptr)
23 return nullptr;
24
25 LIBC_NAMESPACE::cpp::string_view env_var_name(name);
26 if (env_var_name.size() == 0)
27 return nullptr;
28 for (char **env = env_ptr; *env != nullptr; env++) {
29 LIBC_NAMESPACE::cpp::string_view cur(*env);
30 if (!cur.starts_with(env_var_name))
31 continue;
32
33 if (cur[env_var_name.size()] != '=')
34 continue;
35
36 // Remove the name and the equals sign.
37 cur.remove_prefix(env_var_name.size() + 1);
38 // We know that data is null terminated, so this is safe.
39 return const_cast<char *>(cur.data());
40 }
41
42 return nullptr;
43}
44
45} // namespace LIBC_NAMESPACE_DECL

Callers

nothing calls this directly

Calls 4

starts_withMethod · 0.80
remove_prefixMethod · 0.80
sizeMethod · 0.65
dataMethod · 0.45

Tested by

no test coverage detected