summaryrefslogtreecommitdiff
path: root/src/sys/termios.rs
diff options
context:
space:
mode:
authorAlex Saveau <saveau.alexandre@gmail.com>2022-11-06 11:27:08 -0800
committerAlex Saveau <saveau.alexandre@gmail.com>2022-11-06 11:39:09 -0800
commit17833268cb3269d83766bcdb4d9cbe0e25ebd38e (patch)
treeb86885991e1d8b6f9c610747c2e8c3a3370960cd /src/sys/termios.rs
parent20df092bd067908fba23e49120eed7ad62f29108 (diff)
downloadnix-17833268cb3269d83766bcdb4d9cbe0e25ebd38e.zip
Reformat everything
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
Diffstat (limited to 'src/sys/termios.rs')
-rw-r--r--src/sys/termios.rs168
1 files changed, 119 insertions, 49 deletions
diff --git a/src/sys/termios.rs b/src/sys/termios.rs
index 4ff4e674..fba2cd82 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -85,12 +85,28 @@
//!
//! On non-BSDs, `cfgetispeed()` and `cfgetospeed()` both return a `BaudRate`:
//!
-#![cfg_attr(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
- target_os = "macos", target_os = "netbsd", target_os = "openbsd"),
- doc = " ```rust,ignore")]
-#![cfg_attr(not(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
- target_os = "macos", target_os = "netbsd", target_os = "openbsd")),
- doc = " ```rust")]
+#![cfg_attr(
+ any(
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd"
+ ),
+ doc = " ```rust,ignore"
+)]
+#![cfg_attr(
+ not(any(
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd"
+ )),
+ doc = " ```rust"
+)]
//! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetspeed, Termios};
//! # fn main() {
//! # let mut t: Termios = unsafe { std::mem::zeroed() };
@@ -102,12 +118,28 @@
//!
//! But on the BSDs, `cfgetispeed()` and `cfgetospeed()` both return `u32`s:
//!
-#![cfg_attr(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
- target_os = "macos", target_os = "netbsd", target_os = "openbsd"),
- doc = " ```rust")]
-#![cfg_attr(not(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
- target_os = "macos", target_os = "netbsd", target_os = "openbsd")),
- doc = " ```rust,ignore")]
+#![cfg_attr(
+ any(
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd"
+ ),
+ doc = " ```rust"
+)]
+#![cfg_attr(
+ not(any(
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd"
+ )),
+ doc = " ```rust,ignore"
+)]
//! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetspeed, Termios};
//! # fn main() {
//! # let mut t: Termios = unsafe { std::mem::zeroed() };
@@ -119,12 +151,28 @@
//!
//! It's trivial to convert from a `BaudRate` to a `u32` on BSDs:
//!
-#![cfg_attr(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
- target_os = "macos", target_os = "netbsd", target_os = "openbsd"),
- doc = " ```rust")]
-#![cfg_attr(not(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
- target_os = "macos", target_os = "netbsd", target_os = "openbsd")),
- doc = " ```rust,ignore")]
+#![cfg_attr(
+ any(
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd"
+ ),
+ doc = " ```rust"
+)]
+#![cfg_attr(
+ not(any(
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd"
+ )),
+ doc = " ```rust,ignore"
+)]
//! # use nix::sys::termios::{BaudRate, cfgetispeed, cfsetspeed, Termios};
//! # fn main() {
//! # let mut t: Termios = unsafe { std::mem::zeroed() };
@@ -137,12 +185,28 @@
//! And on BSDs you can specify arbitrary baud rates (**note** this depends on hardware support)
//! by specifying baud rates directly using `u32`s:
//!
-#![cfg_attr(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
- target_os = "macos", target_os = "netbsd", target_os = "openbsd"),
- doc = " ```rust")]
-#![cfg_attr(not(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
- target_os = "macos", target_os = "netbsd", target_os = "openbsd")),
- doc = " ```rust,ignore")]
+#![cfg_attr(
+ any(
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd"
+ ),
+ doc = " ```rust"
+)]
+#![cfg_attr(
+ not(any(
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd"
+ )),
+ doc = " ```rust,ignore"
+)]
//! # use nix::sys::termios::{cfsetispeed, cfsetospeed, cfsetspeed, Termios};
//! # fn main() {
//! # let mut t: Termios = unsafe { std::mem::zeroed() };
@@ -151,9 +215,9 @@
//! cfsetspeed(&mut t, 9600u32);
//! # }
//! ```
-use cfg_if::cfg_if;
-use crate::Result;
use crate::errno::Errno;
+use crate::Result;
+use cfg_if::cfg_if;
use libc::{self, c_int, tcflag_t};
use std::cell::{Ref, RefCell};
use std::convert::From;
@@ -182,10 +246,7 @@ pub struct Termios {
/// Control characters (see `termios.c_cc` documentation)
pub control_chars: [libc::cc_t; NCCS],
/// Line discipline (see `termios.c_line` documentation)
- #[cfg(any(
- target_os = "linux",
- target_os = "android",
- ))]
+ #[cfg(any(target_os = "linux", target_os = "android",))]
pub line_discipline: libc::cc_t,
/// Line discipline (see `termios.c_line` documentation)
#[cfg(target_os = "haiku")]
@@ -287,7 +348,7 @@ impl From<Termios> for libc::termios {
}
}
-libc_enum!{
+libc_enum! {
/// Baud rates supported by the system.
///
/// For the BSDs, arbitrary baud rates can be specified by using `u32`s directly instead of this
@@ -402,12 +463,14 @@ libc_enum!{
impl TryFrom<libc::speed_t>
}
-#[cfg(any(target_os = "freebsd",
- target_os = "dragonfly",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd"))]
+#[cfg(any(
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd"
+))]
impl From<BaudRate> for u32 {
fn from(b: BaudRate) -> u32 {
b as u32
@@ -421,7 +484,6 @@ impl From<BaudRate> for u8 {
}
}
-
// TODO: Add TCSASOFT, which will require treating this as a bitfield.
libc_enum! {
/// Specify when a port configuration change should occur.
@@ -538,21 +600,26 @@ libc_enum! {
}
}
-#[cfg(any(all(target_os = "linux", target_arch = "sparc64"),
- target_os = "illumos", target_os = "solaris"))]
+#[cfg(any(
+ all(target_os = "linux", target_arch = "sparc64"),
+ target_os = "illumos",
+ target_os = "solaris"
+))]
impl SpecialCharacterIndices {
pub const VMIN: SpecialCharacterIndices = SpecialCharacterIndices::VEOF;
pub const VTIME: SpecialCharacterIndices = SpecialCharacterIndices::VEOL;
}
pub use libc::NCCS;
-#[cfg(any(target_os = "android",
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "linux",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd"))]
+#[cfg(any(
+ target_os = "android",
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "linux",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd"
+))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub use libc::_POSIX_VDISABLE;
@@ -922,7 +989,7 @@ libc_bitflags! {
}
}
-cfg_if!{
+cfg_if! {
if #[cfg(any(target_os = "freebsd",
target_os = "dragonfly",
target_os = "ios",
@@ -1094,7 +1161,10 @@ pub fn tcgetattr(fd: RawFd) -> Result<Termios> {
/// *any* of the parameters were successfully set, not only if all were set successfully.
pub fn tcsetattr(fd: RawFd, actions: SetArg, termios: &Termios) -> Result<()> {
let inner_termios = termios.get_libc_termios();
- Errno::result(unsafe { libc::tcsetattr(fd, actions as c_int, &*inner_termios) }).map(drop)
+ Errno::result(unsafe {
+ libc::tcsetattr(fd, actions as c_int, &*inner_termios)
+ })
+ .map(drop)
}
/// Block until all output data is written (see