diff options
Diffstat (limited to 'vendor/rustix/tests/fs/openat.rs')
-rw-r--r-- | vendor/rustix/tests/fs/openat.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/vendor/rustix/tests/fs/openat.rs b/vendor/rustix/tests/fs/openat.rs new file mode 100644 index 000000000..564574dc1 --- /dev/null +++ b/vendor/rustix/tests/fs/openat.rs @@ -0,0 +1,33 @@ +use std::fs::File; + +use io_lifetimes::{FromFd, IntoFd}; +use rustix::fs::{cwd, openat, Mode, OFlags}; +use std::io::Write; + +#[test] +fn test_openat_tmpfile() { + let tmp = tempfile::tempdir().unwrap(); + let dir = openat( + cwd(), + tmp.path(), + OFlags::RDONLY | OFlags::CLOEXEC, + Mode::empty(), + ) + .unwrap(); + let f = match openat( + &dir, + ".", + OFlags::WRONLY | OFlags::CLOEXEC | OFlags::TMPFILE, + Mode::from_bits_truncate(0o644), + ) { + Ok(f) => Ok(Some(File::from_fd(f.into_fd()))), + // TODO: Factor out the `Err`, once we no longer support Rust 1.48. + Err(rustix::io::Errno::OPNOTSUPP) + | Err(rustix::io::Errno::ISDIR) + | Err(rustix::io::Errno::NOENT) => Ok(None), + Err(e) => Err(e), + }; + if let Some(mut f) = f.unwrap() { + write!(f, "hello world").unwrap(); + } +} |