From db4452e98bad34a815511e0fafc8b4619b74cc68 Mon Sep 17 00:00:00 2001 From: Tibor Nagy <xnagytibor@gmail.com> Date: Sat, 29 Sep 2018 22:52:12 +0200 Subject: [PATCH] Add termios baud rate functions --- src/header/termios/mod.rs | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/header/termios/mod.rs b/src/header/termios/mod.rs index 017aed160..569736dea 100644 --- a/src/header/termios/mod.rs +++ b/src/header/termios/mod.rs @@ -1,5 +1,7 @@ //! termios implementation, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/termios.h.html +use header::errno; +use platform; use platform::types::*; use platform::{Pal, Sys}; @@ -31,6 +33,44 @@ pub extern "C" fn tcsetattr(fd: c_int, act: c_int, value: *mut termios) -> c_int Sys::tcsetattr(fd, act, value) } +#[no_mangle] +pub extern "C" fn cfgetispeed(termios_p: *const termios) -> speed_t { + unsafe { (*termios_p).__c_ispeed } +} + +#[no_mangle] +pub extern "C" fn cfgetospeed(termios_p: *const termios) -> speed_t { + unsafe { (*termios_p).__c_ospeed } +} + +#[no_mangle] +pub extern "C" fn cfsetispeed(termios_p: *mut termios, speed: speed_t) -> c_int { + match speed as usize { + B0..=B38400 | B57600..=B4000000 => { + unsafe { (*termios_p).__c_ispeed = speed }; + 0 + } + _ => { + unsafe { platform::errno = errno::EINVAL }; + -1 + } + } +} + +#[no_mangle] +pub extern "C" fn cfsetospeed(termios_p: *mut termios, speed: speed_t) -> c_int { + match speed as usize { + B0..=B38400 | B57600..=B4000000 => { + unsafe { (*termios_p).__c_ospeed = speed }; + 0 + } + _ => { + unsafe { platform::errno = errno::EINVAL }; + -1 + } + } +} + pub const VINTR: usize = 0; pub const VQUIT: usize = 1; pub const VERASE: usize = 2; -- GitLab