aboutsummaryrefslogtreecommitdiffstats
path: root/src/pty.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-07-15 02:17:57 -0400
committerJesse Luehrs <doy@tozt.net>2020-07-15 02:17:57 -0400
commit3d54d1f4cb7274280f4e01e101137e91f336bc5c (patch)
tree896ecd9b9bd8696c9818c0779cd1d35876adec84 /src/pty.rs
parent489a8198828be02c92da0c771ae0864915b08e7f (diff)
downloadpty-process-3d54d1f4cb7274280f4e01e101137e91f336bc5c.tar.gz
pty-process-3d54d1f4cb7274280f4e01e101137e91f336bc5c.zip
start of an implementation
Diffstat (limited to 'src/pty.rs')
-rw-r--r--src/pty.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/pty.rs b/src/pty.rs
new file mode 100644
index 0000000..03dd7c1
--- /dev/null
+++ b/src/pty.rs
@@ -0,0 +1,32 @@
+use crate::error::*;
+
+pub struct Pty {
+ master: nix::pty::PtyMaster,
+ slave: std::fs::File,
+}
+
+impl Pty {
+ pub fn new() -> Result<Self> {
+ let master = nix::pty::posix_openpt(
+ nix::fcntl::OFlag::O_RDWR | nix::fcntl::OFlag::O_NOCTTY,
+ )?;
+ nix::pty::grantpt(&master)?;
+ nix::pty::unlockpt(&master)?;
+
+ let name = nix::pty::ptsname_r(&master)?;
+ let slave = std::fs::OpenOptions::new()
+ .read(true)
+ .write(true)
+ .open(name)?;
+
+ Ok(Self { master, slave })
+ }
+
+ pub fn master(&self) -> &nix::pty::PtyMaster {
+ &self.master
+ }
+
+ pub fn slave(&self) -> &std::fs::File {
+ &self.slave
+ }
+}