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

Function fs_read

host/sysenv/sys_fs.cpp:113–128  ·  view source on GitHub ↗

read(fd:i32, buf_ptr, buf_len) -> i32

Source from the content-addressed store, hash-verified

111
112// read(fd:i32, buf_ptr, buf_len) -> i32
113static std::vector<Value> fs_read(Stack& stack) {
114 Frame& frame = stack.frames.top();
115 i32_t fd = std::get<i32_t>(frame.locals[0]);
116 i64_t buf_ptr = get_ptr(frame.locals[1]);
117 i64_t buf_len = get_ptr(frame.locals[2]);
118 FdEntry* e = fd_table.get(fd);
119 if(!e || e->is_dir) return {Value(i32_t(-EBADF))};
120 try {
121 auto sp = mem_span(stack, buf_ptr, buf_len);
122 auto n = sys_read(e->os_fd, sp.data(), sp.size());
123 if(n < 0) return {Value(err_code())};
124 return {Value(i32_t(n))};
125 } catch(...) {
126 return {Value(i32_t(-EFAULT))};
127 }
128}
129
130// write(fd:i32, buf_ptr, buf_len) -> i32
131static std::vector<Value> fs_write(Stack& stack) {

Callers

nothing calls this directly

Calls 6

get_ptrFunction · 0.85
ValueClass · 0.85
mem_spanFunction · 0.85
sys_readFunction · 0.85
err_codeFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected