diff options
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | src/sys/epoll.rs | 1 | ||||
-rw-r--r-- | src/sys/signal.rs | 4 | ||||
-rw-r--r-- | src/sys/termios.rs | 177 |
4 files changed, 177 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e620c50..fd7bb095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added +- Added `::nix::sys::termios::BaudRate` enum to provide portable baudrate + values. ([#518](https://github.com/nix-rust/nix/pull/518)) - Added a new `WaitStatus::PtraceEvent` to support ptrace events on Linux and Android ([([#438](https://github.com/nix-rust/nix/pull/438)) - Added support for POSIX AIO @@ -43,6 +45,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ([#520](https://github.com/nix-rust/nix/pull/520)) ### Changed +- `::nix::sys::termios::{cfgetispeed, cfsetispeed, cfgetospeed, cfsetospeed}` + switched to use `BaudRate` enum from `speed_t`. + ([#518](https://github.com/nix-rust/nix/pull/518)) - `epoll_ctl` now could accept None as argument `event` when op is `EpollOp::EpollCtlDel`. ([#480](https://github.com/nix-rust/nix/pull/480)) diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs index 8632a18d..df48b9af 100644 --- a/src/sys/epoll.rs +++ b/src/sys/epoll.rs @@ -20,6 +20,7 @@ libc_bitflags!( EPOLLRDHUP, #[cfg(target_os = "linux")] // Added in 4.5; not in Android. EPOLLEXCLUSIVE, + #[cfg(not(target_arch = "mips"))] EPOLLWAKEUP, EPOLLONESHOT, EPOLLET, diff --git a/src/sys/signal.rs b/src/sys/signal.rs index a82722dd..10730598 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -467,9 +467,9 @@ impl SigEvent { SigevNotify::SigevKevent{..} => libc::SIGEV_KEVENT, #[cfg(target_os = "freebsd")] SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID, - #[cfg(all(target_os = "linux", target_env = "gnu"))] + #[cfg(all(target_os = "linux", target_env = "gnu", not(target_arch = "mips")))] SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID, - #[cfg(all(target_os = "linux", target_env = "musl"))] + #[cfg(any(all(target_os = "linux", target_env = "musl"), target_arch = "mips"))] SigevNotify::SigevThreadId{..} => 4 // No SIGEV_THREAD_ID defined }; sev.sigev_signo = match sigev_notify { diff --git a/src/sys/termios.rs b/src/sys/termios.rs index 9622f392..e8df1ed9 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -125,6 +125,83 @@ mod ffi { pub c_ospeed: speed_t } + #[derive(Clone, Copy, Debug, PartialEq)] + pub enum BaudRate { + B0, + B50, + B75, + B110, + B134, + B150, + B200, + B300, + B600, + B1200, + B1800, + B2400, + B4800, + B9600, + B19200, + B38400, + B7200, + B14400, + B28800, + B57600, + B76800, + B115200, + B230400, + #[cfg(any(target_os = "netbsd", target_os = "freebsd"))] + B460800, + #[cfg(any(target_os = "netbsd", target_os = "freebsd"))] + B921600, + } + + impl From<speed_t> for BaudRate { + fn from(s: speed_t) -> BaudRate { + + use libc::{ + B0, B50, B75, B110, B134, B150, + B200, B300, B600, B1200, B1800, B2400, + B4800, B9600, B19200, B38400, + B7200, B14400, B28800, B57600, + B76800, B115200, B230400}; + + #[cfg(any(target_os = "netbsd", target_os = "freebsd"))] + use libc::{B460800, B921600}; + + match s { + B0 => BaudRate::B0, + B50 => BaudRate::B50, + B75 => BaudRate::B75, + B110 => BaudRate::B110, + B134 => BaudRate::B134, + B150 => BaudRate::B150, + B200 => BaudRate::B200, + B300 => BaudRate::B300, + B600 => BaudRate::B600, + B1200 => BaudRate::B1200, + B1800 => BaudRate::B1800, + B2400 => BaudRate::B2400, + B4800 => BaudRate::B4800, + B9600 => BaudRate::B9600, + B19200 => BaudRate::B19200, + B38400 => BaudRate::B38400, + B7200 => BaudRate::B7200, + B14400 => BaudRate::B14400, + B28800 => BaudRate::B28800, + B57600 => BaudRate::B57600, + B76800 => BaudRate::B76800, + B115200 => BaudRate::B115200, + B230400 => BaudRate::B230400, + #[cfg(any(target_os = "netbsd", target_os = "freebsd"))] + B460800 => BaudRate::B460800, + #[cfg(any(target_os = "netbsd", target_os = "freebsd"))] + B921600 => BaudRate::B921600, + b @ _ => unreachable!("Invalid baud constant: {}", b), + } + } + } + pub const VEOF: usize = 0; pub const VEOL: usize = 1; pub const VEOL2: usize = 2; @@ -293,6 +370,90 @@ mod ffi { pub c_ospeed: speed_t } + #[derive(Clone, Copy, Debug, PartialEq)] + pub enum BaudRate { + B0, + B50, + B75, + B110, + B134, + B150, + B200, + B300, + B600, + B1200, + B1800, + B2400, + B4800, + B9600, + B19200, + B38400, + B57600, + B115200, + B230400, + B460800, + B500000, + B576000, + B921600, + B1000000, + B1152000, + B1500000, + B2000000, + B2500000, + B3000000, + B3500000, + B4000000, + } + + impl From<speed_t> for BaudRate { + fn from(s: speed_t) -> BaudRate { + + use libc::{ + B0, B50, B75, B110, B134, B150, + B200, B300, B600, B1200, B1800, B2400, + B4800, B9600, B19200, B38400, B57600, + B115200, B230400, B460800, B500000, + B576000, B921600, B1000000, B1152000, + B1500000, B2000000, B2500000, B3000000, + B3500000, B4000000}; + + match s { + B0 => BaudRate::B0, + B50 => BaudRate::B50, + B75 => BaudRate::B75, + B110 => BaudRate::B110, + B134 => BaudRate::B134, + B150 => BaudRate::B150, + B200 => BaudRate::B200, + B300 => BaudRate::B300, + B600 => BaudRate::B600, + B1200 => BaudRate::B1200, + B1800 => BaudRate::B1800, + B2400 => BaudRate::B2400, + B4800 => BaudRate::B4800, + B9600 => BaudRate::B9600, + B19200 => BaudRate::B19200, + B38400 => BaudRate::B38400, + B57600 => BaudRate::B57600, + B115200 => BaudRate::B115200, + B230400 => BaudRate::B230400, + B460800 => BaudRate::B460800, + B500000 => BaudRate::B500000, + B576000 => BaudRate::B576000, + B921600 => BaudRate::B921600, + B1000000 => BaudRate::B1000000, + B1152000 => BaudRate::B1152000, + B1500000 => BaudRate::B1500000, + B2000000 => BaudRate::B2000000, + B2500000 => BaudRate::B2500000, + B3000000 => BaudRate::B3000000, + B3500000 => BaudRate::B3500000, + B4000000 => BaudRate::B4000000, + b @ _ => unreachable!("Invalid baud constant: {}", b), + } + } + } + pub const VEOF: usize = 4; pub const VEOL: usize = 11; pub const VEOL2: usize = 16; @@ -426,27 +587,27 @@ mod ffi { } } -pub fn cfgetispeed(termios: &Termios) -> speed_t { +pub fn cfgetispeed(termios: &Termios) -> BaudRate { unsafe { - ffi::cfgetispeed(termios) + ffi::cfgetispeed(termios).into() } } -pub fn cfgetospeed(termios: &Termios) -> speed_t { +pub fn cfgetospeed(termios: &Termios) -> BaudRate { unsafe { - ffi::cfgetospeed(termios) + ffi::cfgetospeed(termios).into() } } -pub fn cfsetispeed(termios: &mut Termios, speed: speed_t) -> Result<()> { +pub fn cfsetispeed(termios: &mut Termios, baud: BaudRate) -> Result<()> { Errno::result(unsafe { - ffi::cfsetispeed(termios, speed) + ffi::cfsetispeed(termios, baud as speed_t) }).map(drop) } -pub fn cfsetospeed(termios: &mut Termios, speed: speed_t) -> Result<()> { +pub fn cfsetospeed(termios: &mut Termios, baud: BaudRate) -> Result<()> { Errno::result(unsafe { - ffi::cfsetospeed(termios, speed) + ffi::cfsetospeed(termios, baud as speed_t) }).map(drop) } |