Skip to content

Commit 5dd2f39

Browse files
committed
Auto merge of #541 - Susurrus:more_termios, r=alexcrichton
Add cfmakeraw and cfsetspeed This includes implementations for Android. `cfsetspeed` is basically just a back-to-back call to `cfsetispeed` and `cfsetospeed`, both of which seem to do the same thing here, so I just copied that body as well for `cfsetspeed`. The implementation for `cfmakeraw` was taken from the man pages for `termios(3)`.
2 parents b9a0a6a + 39e554f commit 5dd2f39

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/unix/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,10 @@ extern {
835835
pub fn tcdrain(fd: ::c_int) -> ::c_int;
836836
pub fn cfgetispeed(termios: *const ::termios) -> ::speed_t;
837837
pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t;
838+
pub fn cfmakeraw(termios: *mut ::termios);
838839
pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
839840
pub fn cfsetospeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
841+
pub fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
840842
pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int;
841843
pub fn tcsetattr(fd: ::c_int,
842844
optional_actions: ::c_int,

src/unix/notbsd/android/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,16 @@ f! {
752752
pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t {
753753
(*termios).c_cflag & ::CBAUD
754754
}
755+
pub fn cfmakeraw(termios: *mut ::termios) -> () {
756+
(*termios).c_iflag &= !(::IGNBRK | ::BRKINT | ::PARMRK | ::ISTRIP |
757+
::INLCR | ::IGNCR | ::ICRNL | ::IXON);
758+
(*termios).c_oflag &= !::OPOST;
759+
(*termios).c_lflag &= !(::ECHO | ::ECHONL | ::ICANON | ::ISIG |
760+
::IEXTEN);
761+
(*termios).c_cflag &= !(::CSIZE | ::PARENB);
762+
(*termios).c_cflag |= ::CS8;
763+
()
764+
}
755765
pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int {
756766
let cbaud = ::CBAUD;
757767
(*termios).c_cflag = ((*termios).c_cflag & !cbaud) | (speed & cbaud);
@@ -762,6 +772,11 @@ f! {
762772
(*termios).c_cflag = ((*termios).c_cflag & !cbaud) | (speed & cbaud);
763773
return 0
764774
}
775+
pub fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int {
776+
let cbaud = ::CBAUD;
777+
(*termios).c_cflag = ((*termios).c_cflag & !cbaud) | (speed & cbaud);
778+
return 0
779+
}
765780
pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int {
766781
ioctl(fd, ::TCGETS, termios)
767782
}

0 commit comments

Comments
 (0)