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::open_scratch_directory;
5
test_file_isatty(dir_fd: wasip1::Fd)6 unsafe fn test_file_isatty(dir_fd: wasip1::Fd) {
7 // Create a file in the scratch directory and test if it's a tty.
8 let file_fd = wasip1::path_open(dir_fd, 0, "file", wasip1::OFLAGS_CREAT, 0, 0, 0)
9 .expect("opening a file");
10 assert!(
11 file_fd > libc::STDERR_FILENO as wasip1::Fd,
12 "file descriptor range check",
13 );
14 assert_eq!(
15 libc::isatty(file_fd as std::os::raw::c_int),
16 0,
17 "file is a tty"
18 );
19 wasip1::fd_close(file_fd).expect("closing a file");
20 wasip1::path_unlink_file(dir_fd, "file").expect("removing a file");
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_file_isatty(dir_fd) }
44 }
45