xref: /wasmtime-44.0.1/crates/test-programs/src/bin/p2_cli_multiple_preopens.rs (revision 020727d0)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::str;
2 
3 fn main() {
4     dbg!(wasip2::filesystem::preopens::get_directories());
5     unsafe {
6         let p3 = wasip1::fd_prestat_get(3).unwrap();
7         let p4 = wasip1::fd_prestat_get(4).unwrap();
8         let p5 = wasip1::fd_prestat_get(5).unwrap();
9         assert_eq!(wasip1::fd_prestat_get(6).err().unwrap(), wasip1::ERRNO_BADF);
10 
11         assert_eq!(p3.u.dir.pr_name_len, 2);
12         assert_eq!(p4.u.dir.pr_name_len, 2);
13         assert_eq!(p5.u.dir.pr_name_len, 2);
14 
15         let mut buf = [0; 100];
16 
17         wasip1::fd_prestat_dir_name(3, buf.as_mut_ptr(), buf.len()).unwrap();
18         assert_eq!(str::from_utf8(&buf[..2]).unwrap(), "/a");
19         wasip1::fd_prestat_dir_name(4, buf.as_mut_ptr(), buf.len()).unwrap();
20         assert_eq!(str::from_utf8(&buf[..2]).unwrap(), "/b");
21         wasip1::fd_prestat_dir_name(5, buf.as_mut_ptr(), buf.len()).unwrap();
22         assert_eq!(str::from_utf8(&buf[..2]).unwrap(), "/c");
23         assert_eq!(
24             wasip1::fd_prestat_dir_name(6, buf.as_mut_ptr(), buf.len()),
25             Err(wasip1::ERRNO_BADF),
26         );
27     }
28     // ..
29 }
30 

served by {OpenGrok

Last Index Update: Fri May 15 20:09:11 GMT 2026