5
5
#![ feature( io_error_uncategorized) ]
6
6
7
7
use std:: collections:: HashMap ;
8
- use std:: ffi:: { CString , OsString } ;
8
+ use std:: ffi:: OsString ;
9
9
use std:: fs:: {
10
- create_dir, read_dir, read_link, remove_dir, remove_dir_all, remove_file, rename, File ,
11
- OpenOptions ,
10
+ canonicalize , create_dir, read_dir, read_link, remove_dir, remove_dir_all, remove_file, rename,
11
+ File , OpenOptions ,
12
12
} ;
13
13
use std:: io:: { Error , ErrorKind , Read , Result , Seek , SeekFrom , Write } ;
14
14
use std:: path:: { Path , PathBuf } ;
@@ -26,13 +26,7 @@ fn main() {
26
26
test_rename ( ) ;
27
27
test_directory ( ) ;
28
28
test_canonicalize ( ) ;
29
- test_dup_stdout_stderr ( ) ;
30
29
test_from_raw_os_error ( ) ;
31
-
32
- // These all require unix, if the test is changed to no longer `ignore-windows`, move these to a unix test
33
- test_file_open_unix_allow_two_args ( ) ;
34
- test_file_open_unix_needs_three_args ( ) ;
35
- test_file_open_unix_extra_third_arg ( ) ;
36
30
}
37
31
38
32
fn tmp ( ) -> PathBuf {
@@ -101,39 +95,6 @@ fn test_file() {
101
95
remove_file ( & path) . unwrap ( ) ;
102
96
}
103
97
104
- fn test_file_open_unix_allow_two_args ( ) {
105
- use std:: os:: unix:: ffi:: OsStrExt ;
106
-
107
- let path = prepare_with_content ( "test_file_open_unix_allow_two_args.txt" , & [ ] ) ;
108
-
109
- let mut name = path. into_os_string ( ) ;
110
- name. push ( "\0 " ) ;
111
- let name_ptr = name. as_bytes ( ) . as_ptr ( ) . cast :: < libc:: c_char > ( ) ;
112
- let _fd = unsafe { libc:: open ( name_ptr, libc:: O_RDONLY ) } ;
113
- }
114
-
115
- fn test_file_open_unix_needs_three_args ( ) {
116
- use std:: os:: unix:: ffi:: OsStrExt ;
117
-
118
- let path = prepare_with_content ( "test_file_open_unix_needs_three_args.txt" , & [ ] ) ;
119
-
120
- let mut name = path. into_os_string ( ) ;
121
- name. push ( "\0 " ) ;
122
- let name_ptr = name. as_bytes ( ) . as_ptr ( ) . cast :: < libc:: c_char > ( ) ;
123
- let _fd = unsafe { libc:: open ( name_ptr, libc:: O_CREAT , 0o666 ) } ;
124
- }
125
-
126
- fn test_file_open_unix_extra_third_arg ( ) {
127
- use std:: os:: unix:: ffi:: OsStrExt ;
128
-
129
- let path = prepare_with_content ( "test_file_open_unix_extra_third_arg.txt" , & [ ] ) ;
130
-
131
- let mut name = path. into_os_string ( ) ;
132
- name. push ( "\0 " ) ;
133
- let name_ptr = name. as_bytes ( ) . as_ptr ( ) . cast :: < libc:: c_char > ( ) ;
134
- let _fd = unsafe { libc:: open ( name_ptr, libc:: O_RDONLY , 42 ) } ;
135
- }
136
-
137
98
fn test_file_clone ( ) {
138
99
let bytes = b"Hello, World!\n " ;
139
100
let path = prepare_with_content ( "miri_test_fs_file_clone.txt" , bytes) ;
@@ -279,46 +240,6 @@ fn test_symlink() {
279
240
symlink_file. read_to_end ( & mut contents) . unwrap ( ) ;
280
241
assert_eq ! ( bytes, contents. as_slice( ) ) ;
281
242
282
- #[ cfg( unix) ]
283
- {
284
- use std:: os:: unix:: ffi:: OsStrExt ;
285
-
286
- let expected_path = path. as_os_str ( ) . as_bytes ( ) ;
287
-
288
- // Test that the expected string gets written to a buffer of proper
289
- // length, and that a trailing null byte is not written.
290
- let symlink_c_str = CString :: new ( symlink_path. as_os_str ( ) . as_bytes ( ) ) . unwrap ( ) ;
291
- let symlink_c_ptr = symlink_c_str. as_ptr ( ) ;
292
-
293
- // Make the buf one byte larger than it needs to be,
294
- // and check that the last byte is not overwritten.
295
- let mut large_buf = vec ! [ 0xFF ; expected_path. len( ) + 1 ] ;
296
- let res = unsafe {
297
- libc:: readlink ( symlink_c_ptr, large_buf. as_mut_ptr ( ) . cast ( ) , large_buf. len ( ) )
298
- } ;
299
- // Check that the resovled path was properly written into the buf.
300
- assert_eq ! ( & large_buf[ ..( large_buf. len( ) - 1 ) ] , expected_path) ;
301
- assert_eq ! ( large_buf. last( ) , Some ( & 0xFF ) ) ;
302
- assert_eq ! ( res, large_buf. len( ) as isize - 1 ) ;
303
-
304
- // Test that the resolved path is truncated if the provided buffer
305
- // is too small.
306
- let mut small_buf = [ 0u8 ; 2 ] ;
307
- let res = unsafe {
308
- libc:: readlink ( symlink_c_ptr, small_buf. as_mut_ptr ( ) . cast ( ) , small_buf. len ( ) )
309
- } ;
310
- assert_eq ! ( small_buf, & expected_path[ ..small_buf. len( ) ] ) ;
311
- assert_eq ! ( res, small_buf. len( ) as isize ) ;
312
-
313
- // Test that we report a proper error for a missing path.
314
- let bad_path = CString :: new ( "MIRI_MISSING_FILE_NAME" ) . unwrap ( ) ;
315
- let res = unsafe {
316
- libc:: readlink ( bad_path. as_ptr ( ) , small_buf. as_mut_ptr ( ) . cast ( ) , small_buf. len ( ) )
317
- } ;
318
- assert_eq ! ( res, -1 ) ;
319
- assert_eq ! ( Error :: last_os_error( ) . kind( ) , ErrorKind :: NotFound ) ;
320
- }
321
-
322
243
// Test that metadata of a symbolic link (i.e., the file it points to) is correct.
323
244
check_metadata ( bytes, & symlink_path) . unwrap ( ) ;
324
245
// Test that the metadata of a symbolic link is correct when not following it.
@@ -369,7 +290,6 @@ fn test_rename() {
369
290
}
370
291
371
292
fn test_canonicalize ( ) {
372
- use std:: fs:: canonicalize;
373
293
let dir_path = prepare_dir ( "miri_test_fs_dir" ) ;
374
294
create_dir ( & dir_path) . unwrap ( ) ;
375
295
let path = dir_path. join ( "test_file" ) ;
@@ -379,11 +299,6 @@ fn test_canonicalize() {
379
299
assert_eq ! ( p. to_string_lossy( ) . find( '.' ) , None ) ;
380
300
381
301
remove_dir_all ( & dir_path) . unwrap ( ) ;
382
-
383
- // Make sure we get an error for long paths.
384
- use std:: convert:: TryInto ;
385
- let too_long = "x/" . repeat ( libc:: PATH_MAX . try_into ( ) . unwrap ( ) ) ;
386
- assert ! ( canonicalize( too_long) . is_err( ) ) ;
387
302
}
388
303
389
304
fn test_directory ( ) {
@@ -440,16 +355,6 @@ fn test_directory() {
440
355
remove_dir_all ( & dir_path) . unwrap ( ) ;
441
356
}
442
357
443
- fn test_dup_stdout_stderr ( ) {
444
- let bytes = b"hello dup fd\n " ;
445
- unsafe {
446
- let new_stdout = libc:: fcntl ( 1 , libc:: F_DUPFD , 0 ) ;
447
- let new_stderr = libc:: fcntl ( 2 , libc:: F_DUPFD , 0 ) ;
448
- libc:: write ( new_stdout, bytes. as_ptr ( ) as * const libc:: c_void , bytes. len ( ) ) ;
449
- libc:: write ( new_stderr, bytes. as_ptr ( ) as * const libc:: c_void , bytes. len ( ) ) ;
450
- }
451
- }
452
-
453
358
fn test_from_raw_os_error ( ) {
454
359
let code = 6 ; // not a code that std or Miri know
455
360
let error = Error :: from_raw_os_error ( code) ;
0 commit comments