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