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, create_file, open_scratch_directory};
5
test_path_open_create_existing(dir_fd: wasip1::Fd)6 unsafe fn test_path_open_create_existing(dir_fd: wasip1::Fd) {
7 create_file(dir_fd, "file");
8 assert_errno!(
9 wasip1::path_open(
10 dir_fd,
11 0,
12 "file",
13 wasip1::OFLAGS_CREAT | wasip1::OFLAGS_EXCL,
14 0,
15 0,
16 0,
17 )
18 .expect_err("trying to create a file that already exists"),
19 wasip1::ERRNO_EXIST
20 );
21 wasip1::path_unlink_file(dir_fd, "file").expect("removing a file");
22 }
23
main()24 fn main() {
25 let mut args = env::args();
26 let prog = args.next().unwrap();
27 let arg = if let Some(arg) = args.next() {
28 arg
29 } else {
30 eprintln!("usage: {prog} <scratch directory>");
31 process::exit(1);
32 };
33
34 // Open scratch directory
35 let dir_fd = match open_scratch_directory(&arg) {
36 Ok(dir_fd) => dir_fd,
37 Err(err) => {
38 eprintln!("{err}");
39 process::exit(1)
40 }
41 };
42
43 // Run the tests.
44 unsafe { test_path_open_create_existing(dir_fd) }
45 }
46