5
5
#![ feature( io_error_uncategorized) ]
6
6
7
7
use std:: convert:: TryInto ;
8
- use std:: ffi:: CString ;
8
+ use std:: ffi:: { CStr , CString } ;
9
9
use std:: fs:: { canonicalize, remove_dir_all, remove_file, File } ;
10
10
use std:: io:: { Error , ErrorKind , Write } ;
11
11
use std:: os:: unix:: ffi:: OsStrExt ;
@@ -23,20 +23,21 @@ fn main() {
23
23
}
24
24
25
25
fn tmp ( ) -> PathBuf {
26
- std:: env:: var ( "MIRI_TEMP" )
27
- . map ( |tmp| {
28
- // MIRI_TEMP is set outside of our emulated
29
- // program, so it may have path separators that don't
30
- // correspond to our target platform. We normalize them here
31
- // before constructing a `PathBuf`
32
-
33
- #[ cfg( windows) ]
34
- return PathBuf :: from ( tmp. replace ( "/" , "\\ " ) ) ;
35
-
36
- #[ cfg( not( windows) ) ]
37
- return PathBuf :: from ( tmp. replace ( "\\ " , "/" ) ) ;
38
- } )
39
- . unwrap_or_else ( |_| std:: env:: temp_dir ( ) )
26
+ let path = std:: env:: var ( "MIRI_TEMP" )
27
+ . unwrap_or_else ( |_| std:: env:: temp_dir ( ) . into_os_string ( ) . into_string ( ) . unwrap ( ) ) ;
28
+ // These are host paths. We need to convert them to the target.
29
+ let path = CString :: new ( path) . unwrap ( ) ;
30
+ let mut out = Vec :: with_capacity ( 1024 ) ;
31
+
32
+ unsafe {
33
+ extern "Rust" {
34
+ fn miri_host_to_target_path ( path : * const i8 , out : * mut i8 , out_size : usize ) -> usize ;
35
+ }
36
+ let ret = miri_host_to_target_path ( path. as_ptr ( ) , out. as_mut_ptr ( ) , out. capacity ( ) ) ;
37
+ assert_eq ! ( ret, 0 ) ;
38
+ let out = CStr :: from_ptr ( out. as_ptr ( ) ) . to_str ( ) . unwrap ( ) ;
39
+ PathBuf :: from ( out)
40
+ }
40
41
}
41
42
42
43
/// Prepare: compute filename and make sure the file does not exist.
0 commit comments