MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / exec_fd_readdir

Function exec_fd_readdir

crates/test-programs/src/bin/p1_fd_readdir.rs:58–68  ·  view source on GitHub ↗

Return the entries plus a bool indicating EOF.

(fd: wasip1::Fd, cookie: wasip1::Dircookie)

Source from the content-addressed store, hash-verified

56
57/// Return the entries plus a bool indicating EOF.
58unsafe fn exec_fd_readdir(fd: wasip1::Fd, cookie: wasip1::Dircookie) -> (Vec<DirEntry>, bool) {
59 let mut buf: [u8; BUF_LEN] = [0; BUF_LEN];
60 let bufused =
61 wasip1::fd_readdir(fd, buf.as_mut_ptr(), BUF_LEN, cookie).expect("failed fd_readdir");
62 assert!(bufused <= BUF_LEN);
63
64 let sl = slice::from_raw_parts(buf.as_ptr(), bufused);
65 let dirs: Vec<_> = ReadDir::from_slice(sl).collect();
66 let eof = bufused < BUF_LEN;
67 (dirs, eof)
68}
69
70unsafe fn assert_empty_dir(dir_fd: wasip1::Fd) {
71 let stat = wasip1::fd_filestat_get(dir_fd).expect("failed filestat");

Callers 3

assert_empty_dirFunction · 0.85
test_fd_readdirFunction · 0.85
test_fd_readdir_lotsFunction · 0.85

Calls 6

fd_readdirFunction · 0.85
from_sliceFunction · 0.85
collectMethod · 0.80
expectMethod · 0.45
as_mut_ptrMethod · 0.45
as_ptrMethod · 0.45

Tested by 2

test_fd_readdirFunction · 0.68
test_fd_readdir_lotsFunction · 0.68