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

Function fs_open

host/sysenv/sys_fs.cpp:86–100  ·  view source on GitHub ↗

open(path_ptr, path_len, flags:i32, mode:i32) -> i32

Source from the content-addressed store, hash-verified

84
85// open(path_ptr, path_len, flags:i32, mode:i32) -> i32
86static std::vector<Value> fs_open(Stack& stack) {
87 Frame& frame = stack.frames.top();
88 i64_t path_ptr = get_ptr(frame.locals[0]);
89 i64_t path_len = get_ptr(frame.locals[1]);
90 i32_t flags = std::get<i32_t>(frame.locals[2]);
91 i32_t mode = std::get<i32_t>(frame.locals[3]);
92 try {
93 std::string path = mem_string(stack, path_ptr, path_len);
94 int fd = sys_open(path.c_str(), flags, (int)mode);
95 if(fd < 0) return {Value(err_code())};
96 return {Value(fd_table.alloc(fd))};
97 } catch(...) {
98 return {Value(i32_t(-EFAULT))};
99 }
100}
101
102// close(fd:i32) -> i32
103static std::vector<Value> fs_close(Stack& stack) {

Callers

nothing calls this directly

Calls 6

get_ptrFunction · 0.85
mem_stringFunction · 0.85
sys_openFunction · 0.85
ValueClass · 0.85
err_codeFunction · 0.85
allocMethod · 0.80

Tested by

no test coverage detected