use crate::backend::c;
use crate::{backend, io};
use bitflags::bitflags;
#[repr(C)]
#[derive(Clone)]
pub struct Termios {
#[doc(alias = "c_iflag")]
pub input_modes: InputModes,
#[doc(alias = "c_oflag")]
pub output_modes: OutputModes,
#[doc(alias = "c_cflag")]
pub control_modes: ControlModes,
#[doc(alias = "c_lflag")]
pub local_modes: LocalModes,
#[doc(alias = "c_line")]
#[cfg(not(all(linux_raw, any(target_arch = "powerpc", target_arch = "powerpc64"))))]
#[cfg(any(
linux_like,
target_env = "newlib",
target_os = "haiku",
target_os = "fuchsia",
target_os = "redox"
))]
pub line_discipline: c::cc_t,
#[doc(alias = "c_cc")]
pub special_codes: SpecialCodes,
#[doc(alias = "c_line")]
#[cfg(all(linux_raw, any(target_arch = "powerpc", target_arch = "powerpc64")))]
pub line_discipline: c::cc_t,
pub(crate) input_speed: c::speed_t,
pub(crate) output_speed: c::speed_t,
}
impl Termios {
#[doc(alias = "cfmakeraw")]
#[inline]
pub fn make_raw(&mut self) {
backend::termios::syscalls::cfmakeraw(self)
}
#[doc(alias = "c_ispeed")]
#[doc(alias = "cfgetispeed")]
#[doc(alias = "cfgetspeed")]
#[inline]
pub fn input_speed(&self) -> u32 {
#[cfg(any(linux_kernel, bsd))]
{
debug_assert!(u32::try_from(self.input_speed).is_ok());
self.input_speed as u32
}
#[cfg(not(any(linux_kernel, bsd)))]
{
speed::decode(self.input_speed).unwrap()
}
}
#[inline]
pub fn output_speed(&self) -> u32 {
#[cfg(any(linux_kernel, bsd))]
{
debug_assert!(u32::try_from(self.output_speed).is_ok());
self.output_speed as u32
}
#[cfg(not(any(linux_kernel, bsd)))]
{
speed::decode(self.output_speed).unwrap()
}
}
#[doc(alias = "cfsetspeed")]
#[doc(alias = "CBAUD")]
#[doc(alias = "CBAUDEX")]
#[doc(alias = "CIBAUD")]
#[doc(alias = "CIBAUDEX")]
#[inline]
pub fn set_speed(&mut self, new_speed: u32) -> io::Result<()> {
backend::termios::syscalls::set_speed(self, new_speed)
}
#[doc(alias = "c_ispeed")]
#[doc(alias = "cfsetispeed")]
#[doc(alias = "CIBAUD")]
#[doc(alias = "CIBAUDEX")]
#[inline]
pub fn set_input_speed(&mut self, new_speed: u32) -> io::Result<()> {
backend::termios::syscalls::set_input_speed(self, new_speed)
}
#[doc(alias = "c_ospeed")]
#[doc(alias = "cfsetospeed")]
#[doc(alias = "CBAUD")]
#[doc(alias = "CBAUDEX")]
#[inline]
pub fn set_output_speed(&mut self, new_speed: u32) -> io::Result<()> {
backend::termios::syscalls::set_output_speed(self, new_speed)
}
}
impl core::fmt::Debug for Termios {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut d = f.debug_struct("Termios");
d.field("input_modes", &self.input_modes);
d.field("output_modes", &self.output_modes);
d.field("control_modes", &self.control_modes);
d.field("local_modes", &self.local_modes);
#[cfg(any(
linux_like,
target_env = "newlib",
target_os = "haiku",
target_os = "fuchsia",
target_os = "redox"
))]
{
d.field("line_discipline", &self.line_discipline);
}
d.field("special_codes", &self.special_codes);
d.field("input_speed", &self.input_speed());
d.field("output_speed", &self.output_speed());
d.finish()
}
}
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct InputModes: c::tcflag_t {
const IGNBRK = c::IGNBRK;
const BRKINT = c::BRKINT;
const IGNPAR = c::IGNPAR;
const PARMRK = c::PARMRK;
const INPCK = c::INPCK;
const ISTRIP = c::ISTRIP;
const INLCR = c::INLCR;
const IGNCR = c::IGNCR;
const ICRNL = c::ICRNL;
#[cfg(any(linux_kernel, solarish, target_os = "haiku"))]
const IUCLC = c::IUCLC;
const IXON = c::IXON;
#[cfg(not(target_os = "redox"))]
const IXANY = c::IXANY;
const IXOFF = c::IXOFF;
#[cfg(not(any(target_os = "haiku", target_os = "redox")))]
const IMAXBEL = c::IMAXBEL;
#[cfg(not(any(
solarish,
target_os = "aix",
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "haiku",
target_os = "netbsd",
target_os = "openbsd",
target_os = "redox",
)))]
const IUTF8 = c::IUTF8;
}
}
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct OutputModes: c::tcflag_t {
const OPOST = c::OPOST;
#[cfg(not(any(
apple,
target_os = "aix",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "redox",
)))]
const OLCUC = c::OLCUC;
const ONLCR = c::ONLCR;
const OCRNL = c::OCRNL;
const ONOCR = c::ONOCR;
const ONLRET = c::ONLRET;
#[cfg(not(bsd))]
const OFILL = c::OFILL;
#[cfg(not(bsd))]
const OFDEL = c::OFDEL;
#[cfg(not(any(bsd, solarish, target_os = "redox")))]
const NLDLY = c::NLDLY;
#[cfg(not(any(bsd, solarish, target_os = "fuchsia", target_os = "redox")))]
const NL0 = c::NL0;
#[cfg(not(any(bsd, solarish, target_os = "fuchsia", target_os = "redox")))]
const NL1 = c::NL1;
#[cfg(not(any(bsd, solarish, target_os = "redox")))]
const CRDLY = c::CRDLY;
#[cfg(not(any(bsd, solarish, target_os = "fuchsia", target_os = "redox")))]
const CR0 = c::CR0;
#[cfg(not(any(
target_env = "musl",
bsd,
solarish,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "redox",
)))]
const CR1 = c::CR1;
#[cfg(not(any(
target_env = "musl",
bsd,
solarish,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "redox",
)))]
const CR2 = c::CR2;
#[cfg(not(any(
target_env = "musl",
bsd,
solarish,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "redox",
)))]
const CR3 = c::CR3;
#[cfg(not(any(
netbsdlike,
solarish,
target_os = "dragonfly",
target_os = "redox",
)))]
const TABDLY = c::TABDLY;
#[cfg(not(any(
netbsdlike,
solarish,
target_os = "dragonfly",
target_os = "fuchsia",
target_os = "redox",
)))]
const TAB0 = c::TAB0;
#[cfg(not(any(
target_env = "musl",
bsd,
solarish,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "redox",
)))]
const TAB1 = c::TAB1;
#[cfg(not(any(
target_env = "musl",
bsd,
solarish,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "redox",
)))]
const TAB2 = c::TAB2;
#[cfg(not(any(
target_env = "musl",
bsd,
solarish,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "redox",
)))]
const TAB3 = c::TAB3;
#[cfg(not(any(
bsd,
solarish,
target_os = "aix",
target_os = "haiku",
target_os = "redox",
)))]
const XTABS = c::XTABS;
#[cfg(not(any(bsd, solarish, target_os = "redox")))]
const BSDLY = c::BSDLY;
#[cfg(not(any(bsd, solarish, target_os = "fuchsia", target_os = "redox")))]
const BS0 = c::BS0;
#[cfg(not(any(
target_env = "musl",
bsd,
solarish,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "redox",
)))]
const BS1 = c::BS1;
#[cfg(not(any(bsd, solarish, target_os = "redox")))]
const FFDLY = c::FFDLY;
#[cfg(not(any(bsd, solarish, target_os = "fuchsia", target_os = "redox")))]
const FF0 = c::FF0;
#[cfg(not(any(
target_env = "musl",
bsd,
solarish,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "redox",
)))]
const FF1 = c::FF1;
#[cfg(not(any(bsd, solarish, target_os = "redox")))]
const VTDLY = c::VTDLY;
#[cfg(not(any(bsd, solarish, target_os = "fuchsia", target_os = "redox")))]
const VT0 = c::VT0;
#[cfg(not(any(
target_env = "musl",
bsd,
solarish,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "redox",
)))]
const VT1 = c::VT1;
}
}
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct ControlModes: c::tcflag_t {
const CSIZE = c::CSIZE;
const CS5 = c::CS5;
const CS6 = c::CS6;
const CS7 = c::CS7;
const CS8 = c::CS8;
const CSTOPB = c::CSTOPB;
const CREAD = c::CREAD;
const PARENB = c::PARENB;
const PARODD = c::PARODD;
const HUPCL = c::HUPCL;
const CLOCAL = c::CLOCAL;
#[cfg(not(any(target_os = "aix", target_os = "redox")))]
const CRTSCTS = c::CRTSCTS;
#[cfg(not(any(
bsd,
solarish,
target_os = "aix",
target_os = "emscripten",
target_os = "haiku",
target_os = "redox",
)))]
const CMSPAR = c::CMSPAR;
}
}
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct LocalModes: c::tcflag_t {
#[cfg(any(linux_kernel, target_arch = "s390x", target_os = "haiku"))]
const XCASE = c::XCASE;
#[cfg(not(target_os = "redox"))]
const ECHOCTL = c::ECHOCTL;
#[cfg(not(target_os = "redox"))]
const ECHOPRT = c::ECHOPRT;
#[cfg(not(target_os = "redox"))]
const ECHOKE = c::ECHOKE;
#[cfg(not(target_os = "redox"))]
const FLUSHO = c::FLUSHO;
#[cfg(not(target_os = "redox"))]
const PENDIN = c::PENDIN;
#[cfg(not(any(target_os = "aix", target_os = "haiku", target_os = "redox")))]
const EXTPROC = c::EXTPROC;
const ISIG = c::ISIG;
const ICANON = c::ICANON;
const ECHO = c::ECHO;
const ECHOE = c::ECHOE;
const ECHOK = c::ECHOK;
const ECHONL = c::ECHONL;
const NOFLSH = c::NOFLSH;
const TOSTOP = c::TOSTOP;
const IEXTEN = c::IEXTEN;
}
}
pub mod speed {
#[cfg(not(bsd))]
use crate::backend::c;
pub const B0: u32 = 0;
pub const B50: u32 = 50;
pub const B75: u32 = 75;
pub const B110: u32 = 110;
pub const B134: u32 = 134;
pub const B150: u32 = 150;
pub const B200: u32 = 200;
pub const B300: u32 = 300;
pub const B600: u32 = 600;
pub const B1200: u32 = 1200;
pub const B1800: u32 = 1800;
pub const B2400: u32 = 2400;
pub const B4800: u32 = 4800;
pub const B9600: u32 = 9600;
#[doc(alias = "EXTA")]
pub const B19200: u32 = 19200;
#[doc(alias = "EXTB")]
pub const B38400: u32 = 38400;
#[cfg(not(target_os = "aix"))]
pub const B57600: u32 = 57600;
#[cfg(not(target_os = "aix"))]
pub const B115200: u32 = 115_200;
#[cfg(not(target_os = "aix"))]
pub const B230400: u32 = 230_400;
#[cfg(not(any(
apple,
target_os = "aix",
target_os = "dragonfly",
target_os = "haiku",
target_os = "openbsd"
)))]
pub const B460800: u32 = 460_800;
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
pub const B500000: u32 = 500_000;
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
pub const B576000: u32 = 576_000;
#[cfg(not(any(
apple,
target_os = "aix",
target_os = "dragonfly",
target_os = "haiku",
target_os = "openbsd"
)))]
pub const B921600: u32 = 921_600;
#[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "solaris")))]
pub const B1000000: u32 = 1_000_000;
#[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "solaris")))]
pub const B1152000: u32 = 1_152_000;
#[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "solaris")))]
pub const B1500000: u32 = 1_500_000;
#[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "solaris")))]
pub const B2000000: u32 = 2_000_000;
#[cfg(not(any(
target_arch = "sparc",
target_arch = "sparc64",
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "solaris",
)))]
pub const B2500000: u32 = 2_500_000;
#[cfg(not(any(
target_arch = "sparc",
target_arch = "sparc64",
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "solaris",
)))]
pub const B3000000: u32 = 3_000_000;
#[cfg(not(any(
target_arch = "sparc",
target_arch = "sparc64",
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "solaris",
)))]
pub const B3500000: u32 = 3_500_000;
#[cfg(not(any(
target_arch = "sparc",
target_arch = "sparc64",
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "solaris",
)))]
pub const B4000000: u32 = 4_000_000;
#[cfg(not(any(linux_kernel, bsd)))]
pub(crate) fn decode(encoded_speed: c::speed_t) -> Option<u32> {
match encoded_speed {
c::B0 => Some(0),
c::B50 => Some(50),
c::B75 => Some(75),
c::B110 => Some(110),
c::B134 => Some(134),
c::B150 => Some(150),
c::B200 => Some(200),
c::B300 => Some(300),
c::B600 => Some(600),
c::B1200 => Some(1200),
c::B1800 => Some(1800),
c::B2400 => Some(2400),
c::B4800 => Some(4800),
c::B9600 => Some(9600),
c::B19200 => Some(19200),
c::B38400 => Some(38400),
#[cfg(not(target_os = "aix"))]
c::B57600 => Some(57600),
#[cfg(not(target_os = "aix"))]
c::B115200 => Some(115_200),
#[cfg(not(target_os = "aix"))]
c::B230400 => Some(230_400),
#[cfg(not(any(
apple,
target_os = "aix",
target_os = "dragonfly",
target_os = "haiku",
target_os = "openbsd"
)))]
c::B460800 => Some(460_800),
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
c::B500000 => Some(500_000),
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
c::B576000 => Some(576_000),
#[cfg(not(any(
apple,
target_os = "aix",
target_os = "dragonfly",
target_os = "haiku",
target_os = "openbsd"
)))]
c::B921600 => Some(921_600),
#[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "solaris")))]
c::B1000000 => Some(1_000_000),
#[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "solaris")))]
c::B1152000 => Some(1_152_000),
#[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "solaris")))]
c::B1500000 => Some(1_500_000),
#[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "solaris")))]
c::B2000000 => Some(2_000_000),
#[cfg(not(any(
target_arch = "sparc",
target_arch = "sparc64",
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "solaris",
)))]
c::B2500000 => Some(2_500_000),
#[cfg(not(any(
target_arch = "sparc",
target_arch = "sparc64",
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "solaris",
)))]
c::B3000000 => Some(3_000_000),
#[cfg(not(any(
target_arch = "sparc",
target_arch = "sparc64",
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "solaris",
)))]
c::B3500000 => Some(3_500_000),
#[cfg(not(any(
target_arch = "sparc",
target_arch = "sparc64",
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "solaris",
)))]
c::B4000000 => Some(4_000_000),
_ => None,
}
}
#[cfg(not(bsd))]
pub(crate) fn encode(speed: u32) -> Option<c::speed_t> {
match speed {
0 => Some(c::B0),
50 => Some(c::B50),
75 => Some(c::B75),
110 => Some(c::B110),
134 => Some(c::B134),
150 => Some(c::B150),
200 => Some(c::B200),
300 => Some(c::B300),
600 => Some(c::B600),
1200 => Some(c::B1200),
1800 => Some(c::B1800),
2400 => Some(c::B2400),
4800 => Some(c::B4800),
9600 => Some(c::B9600),
19200 => Some(c::B19200),
38400 => Some(c::B38400),
#[cfg(not(target_os = "aix"))]
57600 => Some(c::B57600),
#[cfg(not(target_os = "aix"))]
115_200 => Some(c::B115200),
#[cfg(not(target_os = "aix"))]
230_400 => Some(c::B230400),
#[cfg(not(any(
apple,
target_os = "aix",
target_os = "dragonfly",
target_os = "haiku",
target_os = "openbsd"
)))]
460_800 => Some(c::B460800),
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
500_000 => Some(c::B500000),
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
576_000 => Some(c::B576000),
#[cfg(not(any(
apple,
target_os = "aix",
target_os = "dragonfly",
target_os = "haiku",
target_os = "openbsd"
)))]
921_600 => Some(c::B921600),
#[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "solaris")))]
1_000_000 => Some(c::B1000000),
#[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "solaris")))]
1_152_000 => Some(c::B1152000),
#[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "solaris")))]
1_500_000 => Some(c::B1500000),
#[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "solaris")))]
2_000_000 => Some(c::B2000000),
#[cfg(not(any(
target_arch = "sparc",
target_arch = "sparc64",
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "solaris",
)))]
2_500_000 => Some(c::B2500000),
#[cfg(not(any(
target_arch = "sparc",
target_arch = "sparc64",
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "solaris",
)))]
3_000_000 => Some(c::B3000000),
#[cfg(not(any(
target_arch = "sparc",
target_arch = "sparc64",
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "solaris",
)))]
3_500_000 => Some(c::B3500000),
#[cfg(not(any(
target_arch = "sparc",
target_arch = "sparc64",
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "solaris",
)))]
4_000_000 => Some(c::B4000000),
_ => None,
}
}
}
#[repr(transparent)]
#[derive(Clone, Debug)]
pub struct SpecialCodes(pub(crate) [c::cc_t; c::NCCS as usize]);
impl core::ops::Index<SpecialCodeIndex> for SpecialCodes {
type Output = c::cc_t;
fn index(&self, index: SpecialCodeIndex) -> &Self::Output {
&self.0[index.0]
}
}
impl core::ops::IndexMut<SpecialCodeIndex> for SpecialCodes {
fn index_mut(&mut self, index: SpecialCodeIndex) -> &mut Self::Output {
&mut self.0[index.0]
}
}
pub struct SpecialCodeIndex(usize);
#[rustfmt::skip]
impl SpecialCodeIndex {
pub const VINTR: Self = Self(c::VINTR as usize);
pub const VQUIT: Self = Self(c::VQUIT as usize);
pub const VERASE: Self = Self(c::VERASE as usize);
pub const VKILL: Self = Self(c::VKILL as usize);
pub const VEOF: Self = Self(c::VEOF as usize);
pub const VTIME: Self = Self(c::VTIME as usize);
pub const VMIN: Self = Self(c::VMIN as usize);
#[cfg(not(any(
apple,
solarish,
target_os = "aix",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "netbsd",
target_os = "openbsd",
)))]
pub const VSWTC: Self = Self(c::VSWTC as usize);
pub const VSTART: Self = Self(c::VSTART as usize);
pub const VSTOP: Self = Self(c::VSTOP as usize);
pub const VSUSP: Self = Self(c::VSUSP as usize);
pub const VEOL: Self = Self(c::VEOL as usize);
#[cfg(not(target_os = "haiku"))]
pub const VREPRINT: Self = Self(c::VREPRINT as usize);
#[cfg(not(any(target_os = "aix", target_os = "haiku")))]
pub const VDISCARD: Self = Self(c::VDISCARD as usize);
#[cfg(not(any(target_os = "aix", target_os = "haiku")))]
pub const VWERASE: Self = Self(c::VWERASE as usize);
#[cfg(not(target_os = "haiku"))]
pub const VLNEXT: Self = Self(c::VLNEXT as usize);
pub const VEOL2: Self = Self(c::VEOL2 as usize);
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
#[repr(u32)]
pub enum OptionalActions {
#[doc(alias = "TCSANOW")]
Now = c::TCSANOW as u32,
#[doc(alias = "TCSADRAIN")]
Drain = c::TCSADRAIN as u32,
#[doc(alias = "TCSAFLUSH")]
Flush = c::TCSAFLUSH as u32,
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
#[repr(u32)]
pub enum QueueSelector {
#[doc(alias = "TCIFLUSH")]
IFlush = c::TCIFLUSH as u32,
#[doc(alias = "TCOFLUSH")]
OFlush = c::TCOFLUSH as u32,
#[doc(alias = "TCIOFLUSH")]
IOFlush = c::TCIOFLUSH as u32,
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
#[repr(u32)]
pub enum Action {
#[doc(alias = "TCOOFF")]
OOff = c::TCOOFF as u32,
#[doc(alias = "TCOON")]
OOn = c::TCOON as u32,
#[doc(alias = "TCIOFF")]
IOff = c::TCIOFF as u32,
#[doc(alias = "TCION")]
IOn = c::TCION as u32,
}
#[doc(alias = "winsize")]
pub type Winsize = c::winsize;
#[test]
fn termios_layouts() {
check_renamed_type!(InputModes, tcflag_t);
check_renamed_type!(OutputModes, tcflag_t);
check_renamed_type!(ControlModes, tcflag_t);
check_renamed_type!(LocalModes, tcflag_t);
#[cfg(linux_raw)]
{
check_renamed_type!(Termios, termios2);
check_renamed_struct_renamed_field!(Termios, termios2, input_modes, c_iflag);
check_renamed_struct_renamed_field!(Termios, termios2, output_modes, c_oflag);
check_renamed_struct_renamed_field!(Termios, termios2, control_modes, c_cflag);
check_renamed_struct_renamed_field!(Termios, termios2, local_modes, c_lflag);
check_renamed_struct_renamed_field!(Termios, termios2, line_discipline, c_line);
check_renamed_struct_renamed_field!(Termios, termios2, special_codes, c_cc);
check_renamed_struct_renamed_field!(Termios, termios2, input_speed, c_ispeed);
check_renamed_struct_renamed_field!(Termios, termios2, output_speed, c_ospeed);
check_renamed_struct_renamed_field!(Termios, termios, input_modes, c_iflag);
check_renamed_struct_renamed_field!(Termios, termios, output_modes, c_oflag);
check_renamed_struct_renamed_field!(Termios, termios, control_modes, c_cflag);
check_renamed_struct_renamed_field!(Termios, termios, local_modes, c_lflag);
check_renamed_struct_renamed_field!(Termios, termios, special_codes, c_cc);
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
assert_eq!(
memoffset::offset_of!(Termios, input_speed),
core::mem::size_of::<c::termios>()
);
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
assert_eq!(
core::mem::size_of::<c::termios2>(),
core::mem::size_of::<c::termios>()
);
}
#[cfg(not(linux_raw))]
{
#[cfg(not(all(
target_env = "gnu",
any(
target_arch = "sparc",
target_arch = "sparc64",
target_arch = "mips",
target_arch = "mips64"
)
)))]
check_renamed_type!(Termios, termios);
check_renamed_struct_renamed_field!(Termios, termios, input_modes, c_iflag);
check_renamed_struct_renamed_field!(Termios, termios, output_modes, c_oflag);
check_renamed_struct_renamed_field!(Termios, termios, control_modes, c_cflag);
check_renamed_struct_renamed_field!(Termios, termios, local_modes, c_lflag);
#[cfg(any(
linux_like,
target_env = "newlib",
target_os = "haiku",
target_os = "fuchsia",
target_os = "redox"
))]
check_renamed_struct_renamed_field!(Termios, termios, line_discipline, c_line);
check_renamed_struct_renamed_field!(Termios, termios, special_codes, c_cc);
#[cfg(not(any(
linux_kernel,
solarish,
target_os = "emscripten",
target_os = "fuchsia"
)))]
{
check_renamed_struct_renamed_field!(Termios, termios, input_speed, c_ispeed);
check_renamed_struct_renamed_field!(Termios, termios, output_speed, c_ospeed);
}
#[cfg(any(target_env = "musl", target_os = "fuchsia"))]
{
check_renamed_struct_renamed_field!(Termios, termios, input_speed, __c_ispeed);
check_renamed_struct_renamed_field!(Termios, termios, output_speed, __c_ospeed);
}
}
check_renamed_type!(OptionalActions, c_int);
check_renamed_type!(QueueSelector, c_int);
check_renamed_type!(Action, c_int);
}
#[test]
#[cfg(not(any(solarish, target_os = "emscripten")))]
fn termios_legacy() {
assert_eq!(c::EXTA, c::B19200);
assert_eq!(c::EXTB, c::B38400);
}
#[cfg(bsd)]
#[test]
fn termios_bsd() {
assert_eq!(c::B0, 0);
assert_eq!(c::B50, 50);
assert_eq!(c::B19200, 19200);
assert_eq!(c::B38400, 38400);
}
#[test]
#[cfg(not(bsd))]
fn termios_speed_encoding() {
assert_eq!(speed::encode(0), Some(c::B0));
assert_eq!(speed::encode(50), Some(c::B50));
assert_eq!(speed::encode(19200), Some(c::B19200));
assert_eq!(speed::encode(38400), Some(c::B38400));
assert_eq!(speed::encode(1), None);
assert_eq!(speed::encode(!0), None);
#[cfg(not(linux_kernel))]
{
assert_eq!(speed::decode(c::B0), Some(0));
assert_eq!(speed::decode(c::B50), Some(50));
assert_eq!(speed::decode(c::B19200), Some(19200));
assert_eq!(speed::decode(c::B38400), Some(38400));
}
}
#[cfg(linux_kernel)]
#[test]
fn termios_ioctl_contiguity() {
assert_eq!(c::TCSETS2, c::TCSETS2 + 0);
assert_eq!(c::TCSETSW2, c::TCSETS2 + 1);
assert_eq!(c::TCSETSF2, c::TCSETS2 + 2);
assert_eq!(c::TCSANOW - c::TCSANOW, 0);
assert_eq!(c::TCSADRAIN - c::TCSANOW, 1);
assert_eq!(c::TCSAFLUSH - c::TCSANOW, 2);
#[cfg(any(target_arch = "mips", target_arch = "mips64"))]
{
assert_eq!(i128::from(c::TCSANOW) - i128::from(c::TCSETS), 0);
assert_eq!(i128::from(c::TCSADRAIN) - i128::from(c::TCSETS), 1);
assert_eq!(i128::from(c::TCSAFLUSH) - i128::from(c::TCSETS), 2);
}
#[cfg(not(any(target_arch = "mips", target_arch = "mips64")))]
{
assert_eq!(c::TCSANOW, 0);
assert_eq!(c::TCSADRAIN, 1);
assert_eq!(c::TCSAFLUSH, 2);
}
}
#[cfg(linux_kernel)]
#[test]
fn termios_cibaud() {
assert_eq!(c::CIBAUD, c::CBAUD << c::IBSHIFT);
}