Skip to content

Commit

Permalink
std: Move platform specific stdio code into sys
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Oct 1, 2016
1 parent fea1bd4 commit d311079
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/libstd/io/stdio.rs
Expand Up @@ -125,13 +125,10 @@ impl<R: io::Read> io::Read for Maybe<R> {
}

fn handle_ebadf<T>(r: io::Result<T>, default: T) -> io::Result<T> {
#[cfg(windows)]
const ERR: i32 = ::sys::c::ERROR_INVALID_HANDLE as i32;
#[cfg(not(windows))]
const ERR: i32 = ::libc::EBADF as i32;
use sys::stdio::EBADF_ERR;

match r {
Err(ref e) if e.raw_os_error() == Some(ERR) => Ok(default),
Err(ref e) if e.raw_os_error() == Some(EBADF_ERR) => Ok(default),
r => r
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/sys/unix/stdio.rs
Expand Up @@ -65,3 +65,5 @@ impl io::Write for Stderr {
}
fn flush(&mut self) -> io::Result<()> { Ok(()) }
}

pub const EBADF_ERR: i32 = ::libc::EBADF as i32;
2 changes: 2 additions & 0 deletions src/libstd/sys/windows/stdio.rs
Expand Up @@ -205,3 +205,5 @@ impl Output {
fn invalid_encoding() -> io::Error {
io::Error::new(io::ErrorKind::InvalidData, "text was not valid unicode")
}

pub const EBADF_ERR: i32 = ::sys::c::ERROR_INVALID_HANDLE as i32;

0 comments on commit d311079

Please sign in to comment.