wasmer_wasix/syscalls/wasi/
fd_fdstat_get.rs

1use super::*;
2use crate::syscalls::*;
3
4/// ### `fd_fdstat_get()`
5/// Get metadata of a file descriptor
6/// Input:
7/// - `Fd fd`
8///     The file descriptor whose metadata will be accessed
9/// Output:
10/// - `Fdstat *buf`
11///     The location where the metadata will be written
12#[instrument(level = "trace", skip_all, fields(%fd), ret)]
13pub fn fd_fdstat_get<M: MemorySize>(
14    mut ctx: FunctionEnvMut<'_, WasiEnv>,
15    fd: WasiFd,
16    buf_ptr: WasmPtr<Fdstat, M>,
17) -> Result<Errno, WasiError> {
18    WasiEnv::do_pending_operations(&mut ctx)?;
19
20    let env = ctx.data();
21    let (memory, mut state, inodes) = unsafe { env.get_memory_and_wasi_state_and_inodes(&ctx, 0) };
22    let stat = wasi_try_ok!(state.fs.fdstat(fd));
23
24    let buf = buf_ptr.deref(&memory);
25
26    wasi_try_mem_ok!(buf.write(stat));
27
28    Ok(Errno::Success)
29}