@@ -80,7 +80,7 @@ pub struct OpenOptions {
8080 attributes : u32 ,
8181 share_mode : u32 ,
8282 security_qos_flags : u32 ,
83- security_attributes : * mut c :: SECURITY_ATTRIBUTES ,
83+ inherit_handle : bool ,
8484}
8585
8686#[ derive( Clone , PartialEq , Eq , Debug ) ]
@@ -203,7 +203,7 @@ impl OpenOptions {
203203 share_mode : c:: FILE_SHARE_READ | c:: FILE_SHARE_WRITE | c:: FILE_SHARE_DELETE ,
204204 attributes : 0 ,
205205 security_qos_flags : 0 ,
206- security_attributes : ptr :: null_mut ( ) ,
206+ inherit_handle : false ,
207207 }
208208 }
209209
@@ -243,8 +243,8 @@ impl OpenOptions {
243243 // receive is `SECURITY_ANONYMOUS = 0x0`, which we can't check for later on.
244244 self . security_qos_flags = flags | c:: SECURITY_SQOS_PRESENT ;
245245 }
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 ;
248248 }
249249
250250 fn get_access_mode ( & self ) -> io:: Result < u32 > {
@@ -307,12 +307,17 @@ impl File {
307307
308308 fn open_native ( path : & WCStr , opts : & OpenOptions ) -> io:: Result < File > {
309309 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+ } ;
310315 let handle = unsafe {
311316 c:: CreateFileW (
312317 path. as_ptr ( ) ,
313318 opts. get_access_mode ( ) ?,
314319 opts. share_mode ,
315- opts. security_attributes ,
320+ if opts. inherit_handle { & sa } else { ptr :: null ( ) } ,
316321 creation,
317322 opts. get_flags_and_attributes ( ) ,
318323 ptr:: null_mut ( ) ,
0 commit comments