]> git.lizzy.rs Git - rust.git/blob - tests/run-pass/libc.rs
Try fixing test on i686-unknown-linux-gnu
[rust.git] / tests / run-pass / libc.rs
1 // ignore-windows: No libc on Windows
2 // compile-flags: -Zmiri-disable-isolation
3
4 #![feature(rustc_private)]
5
6 extern crate libc;
7
8 use std::convert::TryInto;
9 use std::env::temp_dir;
10 use std::fs::{File, remove_file};
11 use std::io::Write;
12 use std::os::unix::io::AsRawFd;
13
14 fn main() {
15     let path = temp_dir().join("miri_test_libc.txt");
16     // Cleanup before test
17     remove_file(&path).ok();
18
19     // Set up an open file
20     let mut file = File::create(&path).unwrap();
21     let bytes = b"Hello, World!\n";
22     file.write(bytes).unwrap();
23
24     // Test calling posix_fadvise on a file.
25     let result = unsafe {
26         libc::posix_fadvise(
27             file.as_raw_fd(),
28             0,
29             bytes.len().try_into().unwrap(),
30             libc::POSIX_FADV_DONTNEED,
31         )
32     };
33     drop(file);
34     remove_file(&path).unwrap();
35     assert_eq!(result, 0);
36 }