55#![ feature( io_error_uncategorized) ]
66
77use std:: convert:: TryInto ;
8- use std:: ffi:: CString ;
8+ use std:: ffi:: { CStr , CString } ;
99use std:: fs:: { canonicalize, remove_dir_all, remove_file, File } ;
1010use std:: io:: { Error , ErrorKind , Write } ;
1111use std:: os:: unix:: ffi:: OsStrExt ;
@@ -23,20 +23,21 @@ fn main() {
2323}
2424
2525fn 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+ }
4041}
4142
4243/// Prepare: compute filename and make sure the file does not exist.
0 commit comments