]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass-dep/shims/libc-fs-with-isolation.rs
Unify Opaque/Projection handling in region outlives code
[rust.git] / src / tools / miri / tests / pass-dep / shims / libc-fs-with-isolation.rs
1 //@ignore-target-windows: no libc on Windows
2 //@compile-flags: -Zmiri-isolation-error=warn-nobacktrace
3 //@normalize-stderr-test: "(stat(x)?)" -> "$$STAT"
4
5 use std::ffi::CString;
6 use std::fs;
7 use std::io::{Error, ErrorKind};
8
9 fn main() {
10     // test `fcntl`
11     unsafe {
12         assert_eq!(libc::fcntl(1, libc::F_DUPFD, 0), -1);
13         assert_eq!(Error::last_os_error().raw_os_error(), Some(libc::EPERM));
14     }
15
16     // test `readlink`
17     let symlink_c_str = CString::new("foo.txt").unwrap();
18     let mut buf = vec![0; "foo_link.txt".len() + 1];
19     unsafe {
20         assert_eq!(libc::readlink(symlink_c_str.as_ptr(), buf.as_mut_ptr(), buf.len()), -1);
21         assert_eq!(Error::last_os_error().raw_os_error(), Some(libc::EACCES));
22     }
23
24     // test `stat`
25     assert_eq!(fs::metadata("foo.txt").unwrap_err().kind(), ErrorKind::PermissionDenied);
26     // check that it is the right kind of `PermissionDenied`
27     assert_eq!(Error::last_os_error().raw_os_error(), Some(libc::EACCES));
28 }