]> git.lizzy.rs Git - rust.git/commitdiff
std: Change how EBADF is handled in `sys`
authorAlex Crichton <alex@alexcrichton.com>
Wed, 1 Nov 2017 19:50:13 +0000 (12:50 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 9 Nov 2017 04:41:17 +0000 (20:41 -0800)
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.

src/libstd/io/stdio.rs
src/libstd/sys/redox/stdio.rs
src/libstd/sys/unix/stdio.rs
src/libstd/sys/windows/stdio.rs

index fb489bf487b8bd66db3823874e67166c31f91d52..831688bb73d1cd49bb0528e3599101ddddf42bf6 100644 (file)
@@ -121,10 +121,8 @@ fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
 }
 
 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
     }
 }
index c839531cc26c60838966fb8bc192bb96f46120db..3abb094ac34e3d98af5855f15bbb96f7e63d0982 100644 (file)
@@ -70,5 +70,8 @@ fn flush(&mut self) -> io::Result<()> {
     }
 }
 
-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;
index 7a8fe25d98ee1307b0c3280c5ae2421d690081cf..e9b3d4affc7dd6fcb92505e96a99879529676a68 100644 (file)
@@ -70,5 +70,8 @@ fn flush(&mut self) -> io::Result<()> {
     }
 }
 
-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;
index b5e5b5760f21b9cddcbf70ec5e92b40c6f040a19..b43df20bddd087144faa8b3626de5a72efed7e67 100644 (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