From 39e554f3f8ca0ba501f66275a7586a610d843355 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sun, 26 Feb 2017 13:16:12 -0800 Subject: [PATCH] Add cfmakeraw and cfsetspeed This includes implementations for Android. --- src/unix/mod.rs | 2 ++ src/unix/notbsd/android/mod.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 47edaf1ae13ab..3030f80e095c7 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -835,8 +835,10 @@ extern { pub fn tcdrain(fd: ::c_int) -> ::c_int; pub fn cfgetispeed(termios: *const ::termios) -> ::speed_t; pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t; + pub fn cfmakeraw(termios: *mut ::termios); pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int; pub fn cfsetospeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int; + pub fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int; pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int; pub fn tcsetattr(fd: ::c_int, optional_actions: ::c_int, diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 79d8a537641b2..3884a770786e1 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -752,6 +752,16 @@ f! { pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t { (*termios).c_cflag & ::CBAUD } + pub fn cfmakeraw(termios: *mut ::termios) -> () { + (*termios).c_iflag &= !(::IGNBRK | ::BRKINT | ::PARMRK | ::ISTRIP | + ::INLCR | ::IGNCR | ::ICRNL | ::IXON); + (*termios).c_oflag &= !::OPOST; + (*termios).c_lflag &= !(::ECHO | ::ECHONL | ::ICANON | ::ISIG | + ::IEXTEN); + (*termios).c_cflag &= !(::CSIZE | ::PARENB); + (*termios).c_cflag |= ::CS8; + () + } pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int { let cbaud = ::CBAUD; (*termios).c_cflag = ((*termios).c_cflag & !cbaud) | (speed & cbaud); @@ -762,6 +772,11 @@ f! { (*termios).c_cflag = ((*termios).c_cflag & !cbaud) | (speed & cbaud); return 0 } + pub fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int { + let cbaud = ::CBAUD; + (*termios).c_cflag = ((*termios).c_cflag & !cbaud) | (speed & cbaud); + return 0 + } pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int { ioctl(fd, ::TCGETS, termios) }