File tree Expand file tree Collapse file tree 2 files changed +35
-15
lines changed Expand file tree Collapse file tree 2 files changed +35
-15
lines changed Original file line number Diff line number Diff line change 1
1
// ignore-windows: File handling is not implemented yet
2
2
// compile-flags: -Zmiri-disable-isolation
3
3
4
- #![ feature( rustc_private) ]
5
-
6
- extern crate libc;
7
-
8
4
use std:: fs:: { File , remove_file} ;
9
5
use std:: io:: { Read , Write , ErrorKind , Result } ;
10
- use std:: os:: unix:: io:: AsRawFd ;
11
6
use std:: path:: { PathBuf , Path } ;
12
7
13
8
fn test_metadata ( bytes : & [ u8 ] , path : & Path ) -> Result < ( ) > {
@@ -45,16 +40,6 @@ fn main() {
45
40
file. read_to_end ( & mut contents) . unwrap ( ) ;
46
41
assert_eq ! ( bytes, contents. as_slice( ) ) ;
47
42
48
- // Test calling posix_fadvise on the file.
49
- unsafe {
50
- libc:: posix_fadvise (
51
- file. as_raw_fd ( ) ,
52
- 0 ,
53
- bytes. len ( ) as i64 ,
54
- libc:: POSIX_FADV_DONTNEED ,
55
- ) ;
56
- }
57
-
58
43
// Test that metadata of an absolute path is correct.
59
44
test_metadata ( bytes, & path) . unwrap ( ) ;
60
45
// Test that metadata of a relative path is correct.
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments