]> git.lizzy.rs Git - rust.git/blob - tests/run-pass/libc.rs
Move posix_fadvise test to new libc test file
[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::env::temp_dir;
9 use std::fs::{File, remove_file};
10 use std::io::Write;
11 use std::os::unix::io::AsRawFd;
12
13 fn main() {
14     let path = temp_dir().join("miri_test_libc.txt");
15     // Cleanup before test
16     remove_file(&path).ok();
17
18     // Set up an open file
19     let mut file = File::create(&path).unwrap();
20     let bytes = b"Hello, World!\n";
21     file.write(bytes).unwrap();
22
23     // Test calling posix_fadvise on a file.
24     let result = unsafe {
25         libc::posix_fadvise(
26             file.as_raw_fd(),
27             0,
28             bytes.len() as i64,
29             libc::POSIX_FADV_DONTNEED,
30         )
31     };
32     drop(file);
33     remove_file(&path).unwrap();
34     assert_eq!(result, 0);
35 }