1 #![unstable(issue = "none", feature = "windows_stdio")]
4 use crate::mem::ManuallyDrop;
6 use crate::sys::handle::Handle;
12 const MAX_BUFFER_SIZE: usize = 8192;
13 pub const STDIN_BUF_SIZE: usize = MAX_BUFFER_SIZE / 2 * 3;
15 pub fn get_handle(handle_id: c::DWORD) -> io::Result<c::HANDLE> {
16 let handle = unsafe { c::GetStdHandle(handle_id) };
17 if handle == c::INVALID_HANDLE_VALUE {
18 Err(io::Error::last_os_error())
19 } else if handle.is_null() {
20 Err(io::Error::from_raw_os_error(c::ERROR_INVALID_HANDLE as i32))
26 fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result<usize> {
27 let handle = get_handle(handle_id)?;
28 let handle = Handle::new(handle);
29 ManuallyDrop::new(handle).write(data)
33 pub fn new() -> Stdin {
38 impl io::Read for Stdin {
39 fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
40 let handle = get_handle(c::STD_INPUT_HANDLE)?;
41 let handle = Handle::new(handle);
42 ManuallyDrop::new(handle).read(buf)
47 pub fn new() -> Stdout {
52 impl io::Write for Stdout {
53 fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
54 write(c::STD_OUTPUT_HANDLE, buf)
57 fn flush(&mut self) -> io::Result<()> {
63 pub fn new() -> Stderr {
68 impl io::Write for Stderr {
69 fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
70 write(c::STD_ERROR_HANDLE, buf)
73 fn flush(&mut self) -> io::Result<()> {
78 pub fn is_ebadf(err: &io::Error) -> bool {
79 err.raw_os_error() == Some(c::ERROR_INVALID_HANDLE as i32)
82 pub fn panic_output() -> Option<impl io::Write> {