Skip to content

Commit

Permalink
fmt & clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC committed Dec 7, 2022
1 parent 499b0b7 commit 0fb3a12
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub fn posix_openpt(flags: fcntl::OFlag) -> Result<PtyMaster> {
return Err(Errno::last());
}

Ok(PtyMaster(unsafe {OwnedFd::from_raw_fd(fd) }))
Ok(PtyMaster(unsafe { OwnedFd::from_raw_fd(fd) }))
}

/// Get the name of the slave pseudoterminal (see
Expand Down
31 changes: 25 additions & 6 deletions src/sys/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,9 @@ pub fn cfmakesane(termios: &mut Termios) {
pub fn tcgetattr<Fd: AsFd>(fd: &Fd) -> Result<Termios> {
let mut termios = mem::MaybeUninit::uninit();

let res = unsafe { libc::tcgetattr(fd.as_fd().as_raw_fd(), termios.as_mut_ptr()) };
let res = unsafe {
libc::tcgetattr(fd.as_fd().as_raw_fd(), termios.as_mut_ptr())
};

Errno::result(res)?;

Expand All @@ -1159,10 +1161,18 @@ pub fn tcgetattr<Fd: AsFd>(fd: &Fd) -> Result<Termios> {
/// `tcsetattr()` reconfigures the given port based on a given `Termios` structure. This change
/// takes affect at a time specified by `actions`. Note that this function may return success if
/// *any* of the parameters were successfully set, not only if all were set successfully.
pub fn tcsetattr<Fd: AsFd>(fd: &Fd, actions: SetArg, termios: &Termios) -> Result<()> {
pub fn tcsetattr<Fd: AsFd>(
fd: &Fd,
actions: SetArg,
termios: &Termios,
) -> Result<()> {
let inner_termios = termios.get_libc_termios();
Errno::result(unsafe {
libc::tcsetattr(fd.as_fd().as_raw_fd(), actions as c_int, &*inner_termios)
libc::tcsetattr(
fd.as_fd().as_raw_fd(),
actions as c_int,
&*inner_termios,
)
})
.map(drop)
}
Expand All @@ -1179,7 +1189,10 @@ pub fn tcdrain<Fd: AsFd>(fd: &Fd) -> Result<()> {
/// `tcflow()` suspends of resumes the transmission or reception of data for the given port
/// depending on the value of `action`.
pub fn tcflow<Fd: AsFd>(fd: &Fd, action: FlowArg) -> Result<()> {
Errno::result(unsafe { libc::tcflow(fd.as_fd().as_raw_fd(), action as c_int) }).map(drop)
Errno::result(unsafe {
libc::tcflow(fd.as_fd().as_raw_fd(), action as c_int)
})
.map(drop)
}

/// Discard data in the output or input queue (see
Expand All @@ -1188,7 +1201,10 @@ pub fn tcflow<Fd: AsFd>(fd: &Fd, action: FlowArg) -> Result<()> {
/// `tcflush()` will discard data for a terminal port in the input queue, output queue, or both
/// depending on the value of `action`.
pub fn tcflush<Fd: AsFd>(fd: &Fd, action: FlushArg) -> Result<()> {
Errno::result(unsafe { libc::tcflush(fd.as_fd().as_raw_fd(), action as c_int) }).map(drop)
Errno::result(unsafe {
libc::tcflush(fd.as_fd().as_raw_fd(), action as c_int)
})
.map(drop)
}

/// Send a break for a specific duration (see
Expand All @@ -1197,7 +1213,10 @@ pub fn tcflush<Fd: AsFd>(fd: &Fd, action: FlushArg) -> Result<()> {
/// When using asynchronous data transmission `tcsendbreak()` will transmit a continuous stream
/// of zero-valued bits for an implementation-defined duration.
pub fn tcsendbreak<Fd: AsFd>(fd: &Fd, duration: c_int) -> Result<()> {
Errno::result(unsafe { libc::tcsendbreak(fd.as_fd().as_raw_fd(), duration) }).map(drop)
Errno::result(unsafe {
libc::tcsendbreak(fd.as_fd().as_raw_fd(), duration)
})
.map(drop)
}

feature! {
Expand Down
11 changes: 3 additions & 8 deletions test/sys/test_termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ fn test_tcgetattr_pty() {
#[test]
fn test_tcgetattr_enotty() {
let file = tempfile().unwrap();
assert_eq!(
termios::tcgetattr(&file).err(),
Some(Errno::ENOTTY)
);
assert_eq!(termios::tcgetattr(&file).err(), Some(Errno::ENOTTY));
}

// Test modifying output flags
Expand All @@ -44,8 +41,7 @@ fn test_output_flags() {
// Open one pty to get attributes for the second one
let mut termios = {
let pty = openpty(None, None).expect("openpty failed");
let termios = tcgetattr(&pty.slave).expect("tcgetattr failed");
termios
tcgetattr(&pty.slave).expect("tcgetattr failed")
};

// Make sure postprocessing '\r' isn't specified by default or this test is useless.
Expand Down Expand Up @@ -82,8 +78,7 @@ fn test_local_flags() {
// Open one pty to get attributes for the second one
let mut termios = {
let pty = openpty(None, None).unwrap();
let termios = tcgetattr(&pty.slave).unwrap();
termios
tcgetattr(&pty.slave).unwrap()
};

// Make sure echo is specified by default or this test is useless.
Expand Down
3 changes: 1 addition & 2 deletions test/test_pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ fn test_openpty_with_termios() {
// Open one pty to get attributes for the second one
let mut termios = {
let pty = openpty(None, None).unwrap();
let termios = tcgetattr(&pty.slave).unwrap();
termios
tcgetattr(&pty.slave).unwrap()
};
// Make sure newlines are not transformed so the data is preserved when sent.
termios.output_flags.remove(OutputFlags::ONLCR);
Expand Down

0 comments on commit 0fb3a12

Please sign in to comment.