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, config, open_scratch_directory};
5 
test_symlink_loop(dir_fd: wasip1::Fd)6 unsafe fn test_symlink_loop(dir_fd: wasip1::Fd) {
7     if config().support_dangling_filesystem() {
8         // Create a self-referencing symlink.
9         wasip1::path_symlink("symlink", dir_fd, "symlink").expect("creating a symlink");
10 
11         // Try to open it.
12         assert_errno!(
13             wasip1::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0)
14                 .expect_err("opening a self-referencing symlink"),
15             wasip1::ERRNO_LOOP
16         );
17 
18         // Clean up.
19         wasip1::path_unlink_file(dir_fd, "symlink").expect("removing a file");
20     }
21 }
22 
main()23 fn main() {
24     let mut args = env::args();
25     let prog = args.next().unwrap();
26     let arg = if let Some(arg) = args.next() {
27         arg
28     } else {
29         eprintln!("usage: {prog} <scratch directory>");
30         process::exit(1);
31     };
32 
33     // Open scratch directory
34     let dir_fd = match open_scratch_directory(&arg) {
35         Ok(dir_fd) => dir_fd,
36         Err(err) => {
37             eprintln!("{err}");
38             process::exit(1)
39         }
40     };
41 
42     // Run the tests.
43     unsafe { test_symlink_loop(dir_fd) }
44 }
45