Skip to content

Commit a8ac6d4

Browse files
committed
I/O safety for WinUWP
1 parent b27ccbc commit a8ac6d4

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

library/std/src/sys/windows/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl File {
357357
let mut info: c::FILE_BASIC_INFO = mem::zeroed();
358358
let size = mem::size_of_val(&info);
359359
cvt(c::GetFileInformationByHandleEx(
360-
self.handle.raw(),
360+
self.handle.as_raw_handle(),
361361
c::FileBasicInfo,
362362
&mut info as *mut _ as *mut libc::c_void,
363363
size as c::DWORD,
@@ -385,7 +385,7 @@ impl File {
385385
let mut info: c::FILE_STANDARD_INFO = mem::zeroed();
386386
let size = mem::size_of_val(&info);
387387
cvt(c::GetFileInformationByHandleEx(
388-
self.handle.raw(),
388+
self.handle.as_raw_handle(),
389389
c::FileStandardInfo,
390390
&mut info as *mut _ as *mut libc::c_void,
391391
size as c::DWORD,

library/std/src/sys/windows/stdio_uwp.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use crate::io;
44
use crate::mem::ManuallyDrop;
5+
use crate::os::windows::io::FromRawHandle;
56
use crate::sys::c;
67
use crate::sys::handle::Handle;
78

@@ -25,7 +26,7 @@ pub fn get_handle(handle_id: c::DWORD) -> io::Result<c::HANDLE> {
2526

2627
fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result<usize> {
2728
let handle = get_handle(handle_id)?;
28-
let handle = Handle::new(handle);
29+
let handle = unsafe { Handle::from_raw_handle(handle) };
2930
ManuallyDrop::new(handle).write(data)
3031
}
3132

@@ -38,7 +39,7 @@ impl Stdin {
3839
impl io::Read for Stdin {
3940
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
4041
let handle = get_handle(c::STD_INPUT_HANDLE)?;
41-
let handle = Handle::new(handle);
42+
let handle = unsafe { Handle::from_raw_handle(handle) };
4243
ManuallyDrop::new(handle).read(buf)
4344
}
4445
}

0 commit comments

Comments
 (0)