aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-07-17 03:05:04 -0400
committerJesse Luehrs <doy@tozt.net>2020-07-17 03:05:04 -0400
commit2d3e62e97d1dc80594bdb302426cc226c6a9735c (patch)
treed21373db17c6407f0e36d87278c339c62fcf5f60
parent47f23f518e9b935943b5e71ccd0cbc978aff433f (diff)
downloadpty-process-2d3e62e97d1dc80594bdb302426cc226c6a9735c.tar.gz
pty-process-2d3e62e97d1dc80594bdb302426cc226c6a9735c.zip
move some more code out of unsafe
-rw-r--r--src/command.rs9
-rw-r--r--src/pty.rs10
2 files changed, 7 insertions, 12 deletions
diff --git a/src/command.rs b/src/command.rs
index 3c46739..4f8f808 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -110,11 +110,10 @@ nix::ioctl_write_ptr_bad!(
libc::c_int
);
-fn set_controlling_terminal(fh: &std::fs::File) -> nix::Result<()> {
+fn set_controlling_terminal(file: &std::fs::File) -> nix::Result<()> {
+ let fd = file.as_raw_fd();
// safe because std::fs::File is required to contain a valid file
// descriptor
- unsafe {
- set_controlling_terminal_unsafe(fh.as_raw_fd(), std::ptr::null())
- }
- .map(|_| ())
+ unsafe { set_controlling_terminal_unsafe(fd, std::ptr::null()) }
+ .map(|_| ())
}
diff --git a/src/pty.rs b/src/pty.rs
index 91e6f8c..ad4dfcf 100644
--- a/src/pty.rs
+++ b/src/pty.rs
@@ -100,15 +100,11 @@ nix::ioctl_write_ptr_bad!(
fn set_term_size(file: &std::fs::File, size: &Size) -> nix::Result<()> {
let size = size.into();
+ let fd = file.as_raw_fd();
// safe because std::fs::File is required to contain a valid file
// descriptor and size is guaranteed to be initialized because it's a
// normal rust value, and nix::pty::Winsize is a repr(C) struct with the
// same layout as `struct winsize` from sys/ioctl.h.
- unsafe {
- set_term_size_unsafe(
- file.as_raw_fd(),
- &size as *const nix::pty::Winsize,
- )
- }
- .map(|_| ())
+ unsafe { set_term_size_unsafe(fd, &size as *const nix::pty::Winsize) }
+ .map(|_| ())
}