2
2
//@compile-flags: -Zmiri-disable-isolation
3
3
#![ allow( nonstandard_style) ]
4
4
5
- use std:: io:: { ErrorKind , Read , Write } ;
5
+ use std:: io:: { ErrorKind , Read , Seek , SeekFrom , Write } ;
6
6
use std:: os:: windows:: ffi:: OsStrExt ;
7
- use std:: os:: windows:: io:: { AsRawHandle , FromRawHandle , IntoRawHandle } ;
7
+ use std:: os:: windows:: io:: { AsRawHandle , FromRawHandle } ;
8
8
use std:: path:: Path ;
9
9
use std:: { fs, mem, ptr} ;
10
10
@@ -277,7 +277,13 @@ unsafe fn test_file_read_write() {
277
277
278
278
unsafe fn test_dup_handle ( ) {
279
279
let temp = utils:: tmp ( ) . join ( "test_dup.txt" ) ;
280
- let first_handle = fs:: File :: create ( & temp) . unwrap ( ) . into_raw_handle ( ) ;
280
+
281
+ let mut file1 = fs:: File :: options ( ) . read ( true ) . write ( true ) . create ( true ) . open ( & temp) . unwrap ( ) ;
282
+
283
+ file1. write_all ( b"Hello, World!\n " ) . unwrap ( ) ;
284
+ file1. seek ( SeekFrom :: Start ( 0 ) ) . unwrap ( ) ;
285
+
286
+ let first_handle = file1. as_raw_handle ( ) ;
281
287
282
288
let cur_proc = GetCurrentProcess ( ) ;
283
289
let mut second_handle = mem:: zeroed ( ) ;
@@ -291,11 +297,15 @@ unsafe fn test_dup_handle() {
291
297
DUPLICATE_SAME_ACCESS ,
292
298
) ;
293
299
assert ! ( res != 0 ) ;
294
- let mut file = fs:: File :: from_raw_handle ( second_handle) ;
295
- file. write ( b"Test" ) . unwrap ( ) ;
296
- // Duplicated permissions, so reading fails on the second file
297
- let err = file. read ( & mut [ 0 ] ) . unwrap_err ( ) ;
298
- assert_eq ! ( err. kind( ) , ErrorKind :: PermissionDenied , "I/O Error wrong kind: {:?}" , err) ;
300
+
301
+ let mut buf1 = [ 0 ; 5 ] ;
302
+ file1. read ( & mut buf1) . unwrap ( ) ;
303
+ assert_eq ! ( & buf1, b"Hello" ) ;
304
+
305
+ let mut file2 = fs:: File :: from_raw_handle ( second_handle) ;
306
+ let mut buf2 = [ 0 ; 5 ] ;
307
+ file2. read ( & mut buf2) . unwrap ( ) ;
308
+ assert_eq ! ( & buf2, b", Wor" ) ;
299
309
}
300
310
301
311
unsafe fn test_file_seek ( ) {
0 commit comments