conch_runtime_pshaw/sys/
unix.rs

1//! Extensions and implementations specific to Unix platforms.
2
3use std::io::{Error, ErrorKind, Result};
4
5pub mod io;
6
7pub(crate) trait IsMinusOne {
8    fn is_minus_one(&self) -> bool;
9}
10
11macro_rules! impl_is_minus_one {
12    ($($t:ident)*) => ($(impl IsMinusOne for $t {
13        fn is_minus_one(&self) -> bool {
14            *self == -1
15        }
16    })*)
17}
18
19impl_is_minus_one! { i8 i16 i32 i64 isize }
20
21pub(crate) fn cvt_r<T: IsMinusOne, F: FnMut() -> T>(mut f: F) -> Result<T> {
22    loop {
23        let ret = {
24            let status = f();
25            if status.is_minus_one() {
26                Err(Error::last_os_error())
27            } else {
28                Ok(status)
29            }
30        };
31
32        match ret {
33            Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
34            other => return other,
35        }
36    }
37}