std: Change how EBADF is handled in sys

This commit removes the reexport of `EBADF_ERR` as a constant from
libstd's portability facade, instead opting for a platform-specific
function that specifically queries an `io::Error`. Not all platforms may
have a constant for this, so it makes the intent a little more clear
that a code need not be supplied, just an answer to a query.
This commit is contained in:
Alex Crichton 2017-11-01 12:50:13 -07:00
parent 6bc8f164b0
commit 1ccb50eaa6
4 changed files with 13 additions and 6 deletions

View file

@ -121,10 +121,8 @@ impl<R: io::Read> io::Read for Maybe<R> {
}
fn handle_ebadf<T>(r: io::Result<T>, default: T) -> io::Result<T> {
use sys::stdio::EBADF_ERR;
match r {
Err(ref e) if e.raw_os_error() == Some(EBADF_ERR) => Ok(default),
Err(ref e) if stdio::is_ebadf(e) => Ok(default),
r => r
}
}

View file

@ -70,5 +70,8 @@ impl io::Write for Stderr {
}
}
pub const EBADF_ERR: i32 = ::sys::syscall::EBADF;
pub fn is_ebadf(err: &io::Error) -> bool {
err.raw_os_error() == Some(::sys::syscall::EBADF as i32)
}
pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;

View file

@ -70,5 +70,8 @@ impl io::Write for Stderr {
}
}
pub const EBADF_ERR: i32 = ::libc::EBADF as i32;
pub fn is_ebadf(err: &io::Error) -> bool {
err.raw_os_error() == Some(libc::EBADF as i32)
}
pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;

View file

@ -218,7 +218,10 @@ fn readconsole_input_control(wakeup_mask: c::ULONG) -> c::CONSOLE_READCONSOLE_CO
const CTRL_Z: u8 = 0x1A;
const CTRL_Z_MASK: c::ULONG = 0x4000000; //1 << 0x1A
pub const EBADF_ERR: i32 = ::sys::c::ERROR_INVALID_HANDLE as i32;
pub fn is_ebadf(err: &io::Error) -> bool {
err.raw_os_error() == Some(c::ERROR_INVALID_HANDLE as i32)
}
// The default buffer capacity is 64k, but apparently windows
// doesn't like 64k reads on stdin. See #13304 for details, but the
// idea is that on windows we use a slightly smaller buffer that's