diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9209f0bc79..9535b1fd53 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
([#551](https://github.com/nix-rust/nix/pull/551))
- Added `nix::pty::{grantpt, posix_openpt, ptsname/ptsname_r, unlockpt}`
([#556](https://github.com/nix-rust/nix/pull/556)
+- Added `nix::ptr::openpty`
+ ([#456](https://github.com/nix-rust/nix/pull/456))
### Changed
- Marked `sys::mman::{ mmap, munmap, madvise, munlock, msync }` as unsafe.
diff --git a/src/pty.rs b/src/pty.rs
index 3e9c44ea68..c450e0588b 100644
--- a/src/pty.rs
+++ b/src/pty.rs
@@ -1,12 +1,25 @@
//! Create master and slave virtual pseudo-terminals (PTYs)
+use libc;
+
+pub use libc::pid_t as SessionId;
+pub use libc::winsize as Winsize;
+
use std::ffi::CStr;
use std::mem;
use std::os::unix::prelude::*;
-use libc;
+use sys::termios::Termios;
+use {Errno, Result, Error, fcntl};
+
+/// Representation of a master/slave pty pair
+///
+/// This is returned by `openpty`
+pub struct OpenptyResult {
+ pub master: RawFd,
+ pub slave: RawFd,
+}
-use {Error, fcntl, Result};
/// Representation of the Master device in a master/slave pty pair
///
@@ -162,3 +175,42 @@ pub fn unlockpt(fd: &PtyMaster) -> Result<()> {
Ok(())
}
+
+
+/// Create a new pseudoterminal, returning the slave and master file descriptors
+/// in `OpenptyResult`
+/// (see [openpty](http://man7.org/linux/man-pages/man3/openpty.3.html)).
+///
+/// If `winsize` is not `None`, the window size of the slave will be set to
+/// the values in `winsize`. If `termios` is not `None`, the pseudoterminal's
+/// terminal settings of the slave will be set to the values in `termios`.
+#[inline]
+pub fn openpty<'a, 'b, T: Into