about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-11-01 12:50:13 -0700
committerAlex Crichton <alex@alexcrichton.com>2017-11-08 20:41:17 -0800
commit1ccb50eaa670f86b69e7a64484a8c97e13169183 (patch)
tree77042c08dac06aa8c631a712f34231c782761117 /src/libstd/sys
parent6bc8f164b09b9994e6a2d4c4ca60d7d36c09d3fe (diff)
downloadrust-1ccb50eaa670f86b69e7a64484a8c97e13169183.tar.gz
rust-1ccb50eaa670f86b69e7a64484a8c97e13169183.zip
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.
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/redox/stdio.rs5
-rw-r--r--src/libstd/sys/unix/stdio.rs5
-rw-r--r--src/libstd/sys/windows/stdio.rs5
3 files changed, 12 insertions, 3 deletions
diff --git a/src/libstd/sys/redox/stdio.rs b/src/libstd/sys/redox/stdio.rs
index c839531cc26..3abb094ac34 100644
--- a/src/libstd/sys/redox/stdio.rs
+++ b/src/libstd/sys/redox/stdio.rs
@@ -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;
diff --git a/src/libstd/sys/unix/stdio.rs b/src/libstd/sys/unix/stdio.rs
index 7a8fe25d98e..e9b3d4affc7 100644
--- a/src/libstd/sys/unix/stdio.rs
+++ b/src/libstd/sys/unix/stdio.rs
@@ -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;
diff --git a/src/libstd/sys/windows/stdio.rs b/src/libstd/sys/windows/stdio.rs
index b5e5b5760f2..b43df20bddd 100644
--- a/src/libstd/sys/windows/stdio.rs
+++ b/src/libstd/sys/windows/stdio.rs
@@ -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