From 136bb454d98a9032843259e71f12d8e33cd90f27 Mon Sep 17 00:00:00 2001 From: arcnmx Date: Mon, 25 Jan 2016 21:57:17 -0500 Subject: Errno::result() --- src/sys/event.rs | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'src/sys/event.rs') diff --git a/src/sys/event.rs b/src/sys/event.rs index 6498cb97..eb99f7d9 100644 --- a/src/sys/event.rs +++ b/src/sys/event.rs @@ -1,8 +1,7 @@ /* TOOD: Implement for other kqueue based systems */ -use {Error, Result}; -use errno::Errno; +use errno::{Errno, Result}; #[cfg(not(target_os = "netbsd"))] use libc::{timespec, time_t, c_int, c_long, uintptr_t}; #[cfg(target_os = "netbsd")] @@ -277,11 +276,7 @@ pub const EV_OOBAND: EventFlag = EV_FLAG1; pub fn kqueue() -> Result { let res = unsafe { ffi::kqueue() }; - if res < 0 { - return Err(Error::Sys(Errno::last())); - } - - Ok(res) + Errno::result(res) } pub fn kevent(kq: RawFd, @@ -314,11 +309,7 @@ pub fn kevent_ts(kq: RawFd, if let Some(ref timeout) = timeout_opt {timeout as *const timespec} else {ptr::null()}) }; - if res < 0 { - return Err(Error::Sys(Errno::last())); - } - - return Ok(res as usize) + Errno::result(res).map(|r| r as usize) } #[cfg(target_os = "netbsd")] @@ -337,11 +328,7 @@ pub fn kevent_ts(kq: RawFd, if let Some(ref timeout) = timeout_opt {timeout as *const timespec} else {ptr::null()}) }; - if res < 0 { - return Err(Error::Sys(Errno::last())); - } - - return Ok(res as usize) + Errno::result(res).map(|r| r as usize) } #[cfg(not(target_os = "netbsd"))] -- cgit v1.2.3