Skip to content

Commit cc04cd4

Browse files
committed
rollup merge of #24873: alexcrichton/fix-windows-stdio
Conflicts: src/libstd/sys/windows/fs2.rs
2 parents 873a4e3 + c1149ed commit cc04cd4

File tree

4 files changed

+138
-177
lines changed

4 files changed

+138
-177
lines changed

src/libstd/sys/windows/fs2.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub struct OpenOptions {
6565
share_mode: Option<libc::DWORD>,
6666
creation_disposition: Option<libc::DWORD>,
6767
flags_and_attributes: Option<libc::DWORD>,
68+
security_attributes: usize, // *mut T doesn't have a Default impl
6869
}
6970

7071
#[derive(Clone, PartialEq, Eq, Debug)]
@@ -169,6 +170,9 @@ impl OpenOptions {
169170
pub fn share_mode(&mut self, val: i32) {
170171
self.share_mode = Some(val as libc::DWORD);
171172
}
173+
pub fn security_attributes(&mut self, attrs: libc::LPSECURITY_ATTRIBUTES) {
174+
self.security_attributes = attrs as usize;
175+
}
172176

173177
fn get_desired_access(&self) -> libc::DWORD {
174178
self.desired_access.unwrap_or({
@@ -227,7 +231,7 @@ impl File {
227231
libc::CreateFileW(path.as_ptr(),
228232
opts.get_desired_access(),
229233
opts.get_share_mode(),
230-
ptr::null_mut(),
234+
opts.security_attributes as *mut _,
231235
opts.get_creation_disposition(),
232236
opts.get_flags_and_attributes(),
233237
ptr::null_mut())
@@ -344,6 +348,8 @@ impl File {
344348
Ok(PathBuf::from(OsString::from_wide(subst)))
345349
}
346350
}
351+
352+
pub fn into_handle(self) -> Handle { self.handle }
347353
}
348354

349355
impl FromInner<libc::HANDLE> for File {

src/libstd/sys/windows/handle.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use prelude::v1::*;
1212

1313
use io::ErrorKind;
1414
use io;
15+
use libc::funcs::extra::kernel32::{GetCurrentProcess, DuplicateHandle};
1516
use libc::{self, HANDLE};
1617
use mem;
1718
use ptr;
@@ -65,6 +66,18 @@ impl Handle {
6566
}));
6667
Ok(amt as usize)
6768
}
69+
70+
pub fn duplicate(&self, access: libc::DWORD, inherit: bool,
71+
options: libc::DWORD) -> io::Result<Handle> {
72+
let mut ret = 0 as libc::HANDLE;
73+
try!(cvt(unsafe {
74+
let cur_proc = GetCurrentProcess();
75+
DuplicateHandle(cur_proc, self.0, cur_proc, &mut ret,
76+
access, inherit as libc::BOOL,
77+
options)
78+
}));
79+
Ok(Handle::new(ret))
80+
}
6881
}
6982

7083
impl Drop for Handle {

0 commit comments

Comments
 (0)