1
- //@ignore-target-windows: no libc on Windows
1
+ //@ignore-target-windows: File handling is not implemented yet
2
2
//@compile-flags: -Zmiri-disable-isolation
3
3
4
4
#![ feature( io_error_more) ]
5
5
#![ feature( io_error_uncategorized) ]
6
6
7
7
use std:: ffi:: { CStr , CString , OsString } ;
8
- use std:: fs:: { canonicalize, remove_dir_all , remove_file, File } ;
8
+ use std:: fs:: { canonicalize, remove_file, File } ;
9
9
use std:: io:: { Error , ErrorKind , Write } ;
10
10
use std:: os:: unix:: ffi:: OsStrExt ;
11
11
use std:: os:: unix:: io:: AsRawFd ;
@@ -21,7 +21,6 @@ fn main() {
21
21
test_ftruncate :: < libc:: off_t > ( libc:: ftruncate) ;
22
22
#[ cfg( target_os = "linux" ) ]
23
23
test_ftruncate :: < libc:: off64_t > ( libc:: ftruncate64) ;
24
- test_readlink ( ) ;
25
24
test_file_open_unix_allow_two_args ( ) ;
26
25
test_file_open_unix_needs_three_args ( ) ;
27
26
test_file_open_unix_extra_third_arg ( ) ;
@@ -38,33 +37,8 @@ fn main() {
38
37
test_isatty ( ) ;
39
38
}
40
39
41
- /// Prepare: compute filename and make sure the file does not exist.
42
- fn prepare ( filename : & str ) -> PathBuf {
43
- let path = utils:: tmp ( ) . join ( filename) ;
44
- // Clean the paths for robustness.
45
- remove_file ( & path) . ok ( ) ;
46
- path
47
- }
48
-
49
- /// Prepare directory: compute directory name and make sure it does not exist.
50
- #[ allow( unused) ]
51
- fn prepare_dir ( dirname : & str ) -> PathBuf {
52
- let path = utils:: tmp ( ) . join ( & dirname) ;
53
- // Clean the directory for robustness.
54
- remove_dir_all ( & path) . ok ( ) ;
55
- path
56
- }
57
-
58
- /// Prepare like above, and also write some initial content to the file.
59
- fn prepare_with_content ( filename : & str , content : & [ u8 ] ) -> PathBuf {
60
- let path = prepare ( filename) ;
61
- let mut file = File :: create ( & path) . unwrap ( ) ;
62
- file. write ( content) . unwrap ( ) ;
63
- path
64
- }
65
-
66
40
fn test_file_open_unix_allow_two_args ( ) {
67
- let path = prepare_with_content ( "test_file_open_unix_allow_two_args.txt" , & [ ] ) ;
41
+ let path = utils :: prepare_with_content ( "test_file_open_unix_allow_two_args.txt" , & [ ] ) ;
68
42
69
43
let mut name = path. into_os_string ( ) ;
70
44
name. push ( "\0 " ) ;
@@ -73,7 +47,7 @@ fn test_file_open_unix_allow_two_args() {
73
47
}
74
48
75
49
fn test_file_open_unix_needs_three_args ( ) {
76
- let path = prepare_with_content ( "test_file_open_unix_needs_three_args.txt" , & [ ] ) ;
50
+ let path = utils :: prepare_with_content ( "test_file_open_unix_needs_three_args.txt" , & [ ] ) ;
77
51
78
52
let mut name = path. into_os_string ( ) ;
79
53
name. push ( "\0 " ) ;
@@ -82,7 +56,7 @@ fn test_file_open_unix_needs_three_args() {
82
56
}
83
57
84
58
fn test_file_open_unix_extra_third_arg ( ) {
85
- let path = prepare_with_content ( "test_file_open_unix_extra_third_arg.txt" , & [ ] ) ;
59
+ let path = utils :: prepare_with_content ( "test_file_open_unix_extra_third_arg.txt" , & [ ] ) ;
86
60
87
61
let mut name = path. into_os_string ( ) ;
88
62
name. push ( "\0 " ) ;
@@ -106,49 +80,9 @@ fn test_canonicalize_too_long() {
106
80
assert ! ( canonicalize( too_long) . is_err( ) ) ;
107
81
}
108
82
109
- fn test_readlink ( ) {
110
- let bytes = b"Hello, World!\n " ;
111
- let path = prepare_with_content ( "miri_test_fs_link_target.txt" , bytes) ;
112
- let expected_path = path. as_os_str ( ) . as_bytes ( ) ;
113
-
114
- let symlink_path = prepare ( "miri_test_fs_symlink.txt" ) ;
115
- std:: os:: unix:: fs:: symlink ( & path, & symlink_path) . unwrap ( ) ;
116
-
117
- // Test that the expected string gets written to a buffer of proper
118
- // length, and that a trailing null byte is not written.
119
- let symlink_c_str = CString :: new ( symlink_path. as_os_str ( ) . as_bytes ( ) ) . unwrap ( ) ;
120
- let symlink_c_ptr = symlink_c_str. as_ptr ( ) ;
121
-
122
- // Make the buf one byte larger than it needs to be,
123
- // and check that the last byte is not overwritten.
124
- let mut large_buf = vec ! [ 0xFF ; expected_path. len( ) + 1 ] ;
125
- let res =
126
- unsafe { libc:: readlink ( symlink_c_ptr, large_buf. as_mut_ptr ( ) . cast ( ) , large_buf. len ( ) ) } ;
127
- // Check that the resolved path was properly written into the buf.
128
- assert_eq ! ( & large_buf[ ..( large_buf. len( ) - 1 ) ] , expected_path) ;
129
- assert_eq ! ( large_buf. last( ) , Some ( & 0xFF ) ) ;
130
- assert_eq ! ( res, large_buf. len( ) as isize - 1 ) ;
131
-
132
- // Test that the resolved path is truncated if the provided buffer
133
- // is too small.
134
- let mut small_buf = [ 0u8 ; 2 ] ;
135
- let res =
136
- unsafe { libc:: readlink ( symlink_c_ptr, small_buf. as_mut_ptr ( ) . cast ( ) , small_buf. len ( ) ) } ;
137
- assert_eq ! ( small_buf, & expected_path[ ..small_buf. len( ) ] ) ;
138
- assert_eq ! ( res, small_buf. len( ) as isize ) ;
139
-
140
- // Test that we report a proper error for a missing path.
141
- let bad_path = CString :: new ( "MIRI_MISSING_FILE_NAME" ) . unwrap ( ) ;
142
- let res = unsafe {
143
- libc:: readlink ( bad_path. as_ptr ( ) , small_buf. as_mut_ptr ( ) . cast ( ) , small_buf. len ( ) )
144
- } ;
145
- assert_eq ! ( res, -1 ) ;
146
- assert_eq ! ( Error :: last_os_error( ) . kind( ) , ErrorKind :: NotFound ) ;
147
- }
148
-
149
83
fn test_rename ( ) {
150
- let path1 = prepare ( "miri_test_libc_fs_source.txt" ) ;
151
- let path2 = prepare ( "miri_test_libc_fs_rename_destination.txt" ) ;
84
+ let path1 = utils :: prepare ( "miri_test_libc_fs_source.txt" ) ;
85
+ let path2 = utils :: prepare ( "miri_test_libc_fs_rename_destination.txt" ) ;
152
86
153
87
let file = File :: create ( & path1) . unwrap ( ) ;
154
88
drop ( file) ;
@@ -178,7 +112,7 @@ fn test_ftruncate<T: From<i32>>(
178
112
// https://docs.rs/libc/latest/i686-unknown-linux-gnu/libc/type.off_t.html
179
113
180
114
let bytes = b"hello" ;
181
- let path = prepare ( "miri_test_libc_fs_ftruncate.txt" ) ;
115
+ let path = utils :: prepare ( "miri_test_libc_fs_ftruncate.txt" ) ;
182
116
let mut file = File :: create ( & path) . unwrap ( ) ;
183
117
file. write ( bytes) . unwrap ( ) ;
184
118
file. sync_all ( ) . unwrap ( ) ;
@@ -209,7 +143,7 @@ fn test_ftruncate<T: From<i32>>(
209
143
fn test_o_tmpfile_flag ( ) {
210
144
use std:: fs:: { create_dir, OpenOptions } ;
211
145
use std:: os:: unix:: fs:: OpenOptionsExt ;
212
- let dir_path = prepare_dir ( "miri_test_fs_dir" ) ;
146
+ let dir_path = utils :: prepare_dir ( "miri_test_fs_dir" ) ;
213
147
create_dir ( & dir_path) . unwrap ( ) ;
214
148
// test that the `O_TMPFILE` custom flag gracefully errors instead of stopping execution
215
149
assert_eq ! (
0 commit comments