getenv(name_ptr, name_len, buf_ptr, buf_len) -> i32
| 68 | |
| 69 | // getenv(name_ptr, name_len, buf_ptr, buf_len) -> i32 |
| 70 | static 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 |
| 90 | static std::vector<Value> proc_clock_gettime(Stack& stack) { |
nothing calls this directly
no test coverage detected