1 use std::fs::File;
2
3 use rustix::fs::{cwd, openat, Mode, OFlags};
4 use std::io::Write;
5
6 #[test]
test_openat_tmpfile()7 fn test_openat_tmpfile() {
8 let tmp = tempfile::tempdir().unwrap();
9 let dir = openat(
10 cwd(),
11 tmp.path(),
12 OFlags::RDONLY | OFlags::CLOEXEC,
13 Mode::empty(),
14 )
15 .unwrap();
16 let f = match openat(
17 &dir,
18 ".",
19 OFlags::WRONLY | OFlags::CLOEXEC | OFlags::TMPFILE,
20 Mode::from_bits_truncate(0o644),
21 ) {
22 Ok(f) => Ok(Some(File::from(f))),
23 // TODO: Factor out the `Err`, once we no longer support Rust 1.48.
24 Err(rustix::io::Errno::OPNOTSUPP)
25 | Err(rustix::io::Errno::ISDIR)
26 | Err(rustix::io::Errno::NOENT) => Ok(None),
27 Err(err) => Err(err),
28 };
29 if let Some(mut f) = f.unwrap() {
30 write!(f, "hello world").unwrap();
31 }
32 }
33