Skip to content

Commit 1ccb50e

Browse files
committed
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.
1 parent 6bc8f16 commit 1ccb50e

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

src/libstd/io/stdio.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ impl<R: io::Read> io::Read for Maybe<R> {
121121
}
122122

123123
fn handle_ebadf<T>(r: io::Result<T>, default: T) -> io::Result<T> {
124-
use sys::stdio::EBADF_ERR;
125-
126124
match r {
127-
Err(ref e) if e.raw_os_error() == Some(EBADF_ERR) => Ok(default),
125+
Err(ref e) if stdio::is_ebadf(e) => Ok(default),
128126
r => r
129127
}
130128
}

src/libstd/sys/redox/stdio.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,8 @@ impl io::Write for Stderr {
7070
}
7171
}
7272

73-
pub const EBADF_ERR: i32 = ::sys::syscall::EBADF;
73+
pub fn is_ebadf(err: &io::Error) -> bool {
74+
err.raw_os_error() == Some(::sys::syscall::EBADF as i32)
75+
}
76+
7477
pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;

src/libstd/sys/unix/stdio.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,8 @@ impl io::Write for Stderr {
7070
}
7171
}
7272

73-
pub const EBADF_ERR: i32 = ::libc::EBADF as i32;
73+
pub fn is_ebadf(err: &io::Error) -> bool {
74+
err.raw_os_error() == Some(libc::EBADF as i32)
75+
}
76+
7477
pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;

src/libstd/sys/windows/stdio.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ fn readconsole_input_control(wakeup_mask: c::ULONG) -> c::CONSOLE_READCONSOLE_CO
218218
const CTRL_Z: u8 = 0x1A;
219219
const CTRL_Z_MASK: c::ULONG = 0x4000000; //1 << 0x1A
220220

221-
pub const EBADF_ERR: i32 = ::sys::c::ERROR_INVALID_HANDLE as i32;
221+
pub fn is_ebadf(err: &io::Error) -> bool {
222+
err.raw_os_error() == Some(c::ERROR_INVALID_HANDLE as i32)
223+
}
224+
222225
// The default buffer capacity is 64k, but apparently windows
223226
// doesn't like 64k reads on stdin. See #13304 for details, but the
224227
// idea is that on windows we use a slightly smaller buffer that's

0 commit comments

Comments
 (0)