1 #![expect(unsafe_op_in_unsafe_fn, reason = "old code, not worth updating yet")]
2 
3 use std::{env, process};
4 use test_programs::preview1::{assert_errno, open_scratch_directory};
5 
test_path_open_missing(dir_fd: wasip1::Fd)6 unsafe fn test_path_open_missing(dir_fd: wasip1::Fd) {
7     assert_errno!(
8         wasip1::path_open(
9             dir_fd, 0, "file", 0, // not passing O_CREAT here
10             0, 0, 0,
11         )
12         .expect_err("trying to open a file that doesn't exist"),
13         wasip1::ERRNO_NOENT
14     );
15 }
16 
main()17 fn main() {
18     let mut args = env::args();
19     let prog = args.next().unwrap();
20     let arg = if let Some(arg) = args.next() {
21         arg
22     } else {
23         eprintln!("usage: {prog} <scratch directory>");
24         process::exit(1);
25     };
26 
27     // Open scratch directory
28     let dir_fd = match open_scratch_directory(&arg) {
29         Ok(dir_fd) => dir_fd,
30         Err(err) => {
31             eprintln!("{err}");
32             process::exit(1)
33         }
34     };
35 
36     // Run the tests.
37     unsafe { test_path_open_missing(dir_fd) }
38 }
39