@@ -80,7 +80,7 @@ pub struct OpenOptions {
80
80
attributes : u32 ,
81
81
share_mode : u32 ,
82
82
security_qos_flags : u32 ,
83
- security_attributes : * mut c :: SECURITY_ATTRIBUTES ,
83
+ inherit_handle : bool ,
84
84
}
85
85
86
86
#[ derive( Clone , PartialEq , Eq , Debug ) ]
@@ -203,7 +203,7 @@ impl OpenOptions {
203
203
share_mode : c:: FILE_SHARE_READ | c:: FILE_SHARE_WRITE | c:: FILE_SHARE_DELETE ,
204
204
attributes : 0 ,
205
205
security_qos_flags : 0 ,
206
- security_attributes : ptr :: null_mut ( ) ,
206
+ inherit_handle : false ,
207
207
}
208
208
}
209
209
@@ -243,8 +243,8 @@ impl OpenOptions {
243
243
// receive is `SECURITY_ANONYMOUS = 0x0`, which we can't check for later on.
244
244
self . security_qos_flags = flags | c:: SECURITY_SQOS_PRESENT ;
245
245
}
246
- pub fn security_attributes ( & mut self , attrs : * mut c :: SECURITY_ATTRIBUTES ) {
247
- self . security_attributes = attrs ;
246
+ pub fn inherit_handle ( & mut self , inherit : bool ) {
247
+ self . inherit_handle = inherit ;
248
248
}
249
249
250
250
fn get_access_mode ( & self ) -> io:: Result < u32 > {
@@ -307,12 +307,17 @@ impl File {
307
307
308
308
fn open_native ( path : & WCStr , opts : & OpenOptions ) -> io:: Result < File > {
309
309
let creation = opts. get_creation_mode ( ) ?;
310
+ let sa = c:: SECURITY_ATTRIBUTES {
311
+ nLength : size_of :: < c:: SECURITY_ATTRIBUTES > ( ) as u32 ,
312
+ lpSecurityDescriptor : ptr:: null_mut ( ) ,
313
+ bInheritHandle : opts. inherit_handle as c:: BOOL ,
314
+ } ;
310
315
let handle = unsafe {
311
316
c:: CreateFileW (
312
317
path. as_ptr ( ) ,
313
318
opts. get_access_mode ( ) ?,
314
319
opts. share_mode ,
315
- opts. security_attributes ,
320
+ if opts. inherit_handle { & sa } else { ptr :: null ( ) } ,
316
321
creation,
317
322
opts. get_flags_and_attributes ( ) ,
318
323
ptr:: null_mut ( ) ,
0 commit comments