Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
extern crate libc;

use std::io;
use std::mem;
use std::mem::MaybeUninit;
use std::ops::{Deref,DerefMut};
use std::os::unix::io::RawFd;

Expand Down Expand Up @@ -187,10 +187,12 @@ impl Termios {
///
/// `fd` must be an open file descriptor for a terminal device.
pub fn from_fd(fd: RawFd) -> io::Result<Self> {
let mut termios = unsafe { mem::uninitialized() };
let mut termios = MaybeUninit::uninit();

match tcgetattr(fd, &mut termios) {
Ok(_) => Ok(termios),
// We can’t use tcgetattr() here because Termios can only be safely initialised with a
// valid ::os::target::termios.
match io_result(unsafe { ffi::tcgetattr(fd, termios.as_mut_ptr()) }) {
Ok(()) => Ok(Termios { inner: unsafe { termios.assume_init() } }),
Err(err) => Err(err)
}
}
Expand Down Expand Up @@ -224,9 +226,9 @@ impl DerefMut for Termios {
/// # Examples
///
/// ```
/// # use std::mem;
/// # use std::mem::MaybeUninit;
/// # use termios::{Termios,B9600,cfsetispeed,cfgetispeed};
/// # let mut termios = unsafe { mem::uninitialized() };
/// # let mut termios = unsafe { MaybeUninit::uninit().assume_init() };
/// cfsetispeed(&mut termios, B9600).unwrap();
/// assert_eq!(cfgetispeed(&termios), B9600);
/// ```
Expand All @@ -239,9 +241,9 @@ pub fn cfgetispeed(termios: &Termios) -> speed_t {
/// # Examples
///
/// ```
/// # use std::mem;
/// # use std::mem::MaybeUninit;
/// # use termios::{Termios,B9600,cfsetospeed,cfgetospeed};
/// # let mut termios = unsafe { mem::uninitialized() };
/// # let mut termios = unsafe { MaybeUninit::uninit().assume_init() };
/// cfsetospeed(&mut termios, B9600).unwrap();
/// assert_eq!(cfgetospeed(&termios), B9600);
/// ```
Expand Down Expand Up @@ -281,9 +283,9 @@ pub fn cfgetospeed(termios: &Termios) -> speed_t {
/// # Examples
///
/// ```
/// # use std::mem;
/// # use std::mem::MaybeUninit;
/// # use termios::{Termios,B9600,cfsetispeed,cfgetispeed};
/// # let mut termios = unsafe { mem::uninitialized() };
/// # let mut termios = unsafe { MaybeUninit::uninit().assume_init() };
/// cfsetispeed(&mut termios, B9600).unwrap();
/// assert_eq!(cfgetispeed(&termios), B9600);
/// ```
Expand Down Expand Up @@ -324,9 +326,9 @@ pub fn cfsetispeed(termios: &mut Termios, speed: speed_t) -> io::Result<()> {
/// # Examples
///
/// ```
/// # use std::mem;
/// # use std::mem::MaybeUninit;
/// # use termios::{Termios,B9600,cfsetospeed,cfgetospeed};
/// # let mut termios = unsafe { mem::uninitialized() };
/// # let mut termios = unsafe { MaybeUninit::uninit().assume_init() };
/// cfsetospeed(&mut termios, B9600).unwrap();
/// assert_eq!(cfgetospeed(&termios), B9600);
/// ```
Expand Down Expand Up @@ -364,9 +366,9 @@ pub fn cfsetospeed(termios: &mut Termios, speed: speed_t) -> io::Result<()> {
/// # Examples
///
/// ```
/// # use std::mem;
/// # use std::mem::MaybeUninit;
/// # use termios::{Termios,B9600,cfsetspeed,cfgetispeed,cfgetospeed};
/// # let mut termios = unsafe { mem::uninitialized() };
/// # let mut termios = unsafe { MaybeUninit::uninit().assume_init() };
/// cfsetspeed(&mut termios, B9600).unwrap();
/// assert_eq!(cfgetispeed(&termios), B9600);
/// assert_eq!(cfgetospeed(&termios), B9600);
Expand Down