MCPcopy Create free account
hub / github.com/WasmVM/WasmVM / proc_getenv

Function proc_getenv

host/sysenv/sys_proc.cpp:70–87  ·  view source on GitHub ↗

getenv(name_ptr, name_len, buf_ptr, buf_len) -> i32

Source from the content-addressed store, hash-verified

68
69// getenv(name_ptr, name_len, buf_ptr, buf_len) -> i32
70static std::vector<Value> proc_getenv(Stack& stack) {
71 Frame& frame = stack.frames.top();
72 i64_t name_ptr = get_ptr(frame.locals[0]);
73 i64_t name_len = get_ptr(frame.locals[1]);
74 i64_t buf_ptr = get_ptr(frame.locals[2]);
75 i64_t buf_len = get_ptr(frame.locals[3]);
76 try {
77 std::string name = mem_string(stack, name_ptr, name_len);
78 const char* val = std::getenv(name.c_str());
79 if(val == nullptr) return {Value(i32_t(-ENOENT))};
80 size_t val_len = std::strlen(val);
81 if((size_t)buf_len < val_len + 1) return {Value(i32_t(-ERANGE))};
82 mem_write(stack, buf_ptr, val, val_len + 1);
83 return {Value(i32_t(val_len))};
84 } catch(...) {
85 return {Value(i32_t(-EFAULT))};
86 }
87}
88
89// clock_gettime(clk_id:i32, ts_ptr) -> i32
90static std::vector<Value> proc_clock_gettime(Stack& stack) {

Callers

nothing calls this directly

Calls 4

get_ptrFunction · 0.85
mem_stringFunction · 0.85
ValueClass · 0.85
mem_writeFunction · 0.85

Tested by

no test coverage detected