Reason safety for unsafe blocks for uwp stdin

This commit is contained in:
bdbai 2021-09-23 07:29:52 +08:00
parent a8ac6d471e
commit 4e01157969

View file

@ -26,6 +26,7 @@ pub fn get_handle(handle_id: c::DWORD) -> io::Result<c::HANDLE> {
fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result<usize> {
let handle = get_handle(handle_id)?;
// SAFETY: The handle returned from `get_handle` must be valid and non-null.
let handle = unsafe { Handle::from_raw_handle(handle) };
ManuallyDrop::new(handle).write(data)
}
@ -39,6 +40,7 @@ impl Stdin {
impl io::Read for Stdin {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let handle = get_handle(c::STD_INPUT_HANDLE)?;
// SAFETY: The handle returned from `get_handle` must be valid and non-null.
let handle = unsafe { Handle::from_raw_handle(handle) };
ManuallyDrop::new(handle).read(buf)
}