-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #1155 - divergentdave:shim-posix_fadivse, r=RalfJung
Add no-op shim for posix_fadvise This function is present in the libc crate, but not exposed through the standard library anywhere, so I haven't included a test for it.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// ignore-windows: No libc on Windows | ||
// compile-flags: -Zmiri-disable-isolation | ||
|
||
#![feature(rustc_private)] | ||
|
||
#[allow(unused)] // necessary on macos due to conditional compilation | ||
extern crate libc; | ||
|
||
#[cfg(not(target_os = "macos"))] | ||
fn test_posix_fadvise() { | ||
use std::convert::TryInto; | ||
use std::env::temp_dir; | ||
use std::fs::{File, remove_file}; | ||
use std::io::Write; | ||
use std::os::unix::io::AsRawFd; | ||
|
||
let path = temp_dir().join("miri_test_libc.txt"); | ||
// Cleanup before test | ||
remove_file(&path).ok(); | ||
|
||
// Set up an open file | ||
let mut file = File::create(&path).unwrap(); | ||
let bytes = b"Hello, World!\n"; | ||
file.write(bytes).unwrap(); | ||
|
||
// Test calling posix_fadvise on a file. | ||
let result = unsafe { | ||
libc::posix_fadvise( | ||
file.as_raw_fd(), | ||
0, | ||
bytes.len().try_into().unwrap(), | ||
libc::POSIX_FADV_DONTNEED, | ||
) | ||
}; | ||
drop(file); | ||
remove_file(&path).unwrap(); | ||
assert_eq!(result, 0); | ||
} | ||
|
||
fn main() { | ||
#[cfg(not(target_os = "macos"))] | ||
test_posix_fadvise(); | ||
} |