@@ -6,29 +6,8 @@ use std::fs::{remove_file, File};
6
6
use std:: os:: unix:: io:: AsRawFd ;
7
7
use std:: path:: PathBuf ;
8
8
9
- fn tmp ( ) -> PathBuf {
10
- use std:: ffi:: { c_char, CStr , CString } ;
11
-
12
- let path = std:: env:: var ( "MIRI_TEMP" )
13
- . unwrap_or_else ( |_| std:: env:: temp_dir ( ) . into_os_string ( ) . into_string ( ) . unwrap ( ) ) ;
14
- // These are host paths. We need to convert them to the target.
15
- let path = CString :: new ( path) . unwrap ( ) ;
16
- let mut out = Vec :: with_capacity ( 1024 ) ;
17
-
18
- unsafe {
19
- extern "Rust" {
20
- fn miri_host_to_target_path (
21
- path : * const c_char ,
22
- out : * mut c_char ,
23
- out_size : usize ,
24
- ) -> usize ;
25
- }
26
- let ret = miri_host_to_target_path ( path. as_ptr ( ) , out. as_mut_ptr ( ) , out. capacity ( ) ) ;
27
- assert_eq ! ( ret, 0 ) ;
28
- let out = CStr :: from_ptr ( out. as_ptr ( ) ) . to_str ( ) . unwrap ( ) ;
29
- PathBuf :: from ( out)
30
- }
31
- }
9
+ #[ path = "../../utils/mod.rs" ]
10
+ mod utils;
32
11
33
12
/// Test allocating variant of `realpath`.
34
13
fn test_posix_realpath_alloc ( ) {
@@ -38,7 +17,7 @@ fn test_posix_realpath_alloc() {
38
17
use std:: os:: unix:: ffi:: OsStringExt ;
39
18
40
19
let buf;
41
- let path = tmp ( ) . join ( "miri_test_libc_posix_realpath_alloc" ) ;
20
+ let path = utils :: tmp ( ) . join ( "miri_test_libc_posix_realpath_alloc" ) ;
42
21
let c_path = CString :: new ( path. as_os_str ( ) . as_bytes ( ) ) . expect ( "CString::new failed" ) ;
43
22
44
23
// Cleanup before test.
@@ -63,7 +42,7 @@ fn test_posix_realpath_noalloc() {
63
42
use std:: ffi:: { CStr , CString } ;
64
43
use std:: os:: unix:: ffi:: OsStrExt ;
65
44
66
- let path = tmp ( ) . join ( "miri_test_libc_posix_realpath_noalloc" ) ;
45
+ let path = utils :: tmp ( ) . join ( "miri_test_libc_posix_realpath_noalloc" ) ;
67
46
let c_path = CString :: new ( path. as_os_str ( ) . as_bytes ( ) ) . expect ( "CString::new failed" ) ;
68
47
69
48
let mut v = vec ! [ 0 ; libc:: PATH_MAX as usize ] ;
@@ -103,7 +82,7 @@ fn test_posix_realpath_errors() {
103
82
fn test_posix_fadvise ( ) {
104
83
use std:: io:: Write ;
105
84
106
- let path = tmp ( ) . join ( "miri_test_libc_posix_fadvise.txt" ) ;
85
+ let path = utils :: tmp ( ) . join ( "miri_test_libc_posix_fadvise.txt" ) ;
107
86
// Cleanup before test
108
87
remove_file ( & path) . ok ( ) ;
109
88
@@ -130,7 +109,7 @@ fn test_posix_fadvise() {
130
109
fn test_sync_file_range ( ) {
131
110
use std:: io:: Write ;
132
111
133
- let path = tmp ( ) . join ( "miri_test_libc_sync_file_range.txt" ) ;
112
+ let path = utils :: tmp ( ) . join ( "miri_test_libc_sync_file_range.txt" ) ;
134
113
// Cleanup before test.
135
114
remove_file ( & path) . ok ( ) ;
136
115
@@ -243,7 +222,7 @@ fn test_isatty() {
243
222
libc:: isatty ( libc:: STDERR_FILENO ) ;
244
223
245
224
// But when we open a file, it is definitely not a TTY.
246
- let path = tmp ( ) . join ( "notatty.txt" ) ;
225
+ let path = utils :: tmp ( ) . join ( "notatty.txt" ) ;
247
226
// Cleanup before test.
248
227
remove_file ( & path) . ok ( ) ;
249
228
let file = File :: create ( & path) . unwrap ( ) ;
0 commit comments