summaryrefslogtreecommitdiff
path: root/src/sys/termios.rs
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2015-03-14 04:34:24 +0800
committerCarl Lerche <me@carllerche.com>2015-03-13 16:40:28 -0700
commitc5bc33200c8eb3563784c0e18dc37060049247cd (patch)
tree8715258b03eef8fcc6a62c82582b537ccb219e44 /src/sys/termios.rs
parent386dfd6f4770770b7721e7fa5195b4c993aa3e4b (diff)
downloadnix-c5bc33200c8eb3563784c0e18dc37060049247cd.zip
Amend some files to make it compile on arm-linux-androideabi.
Diffstat (limited to 'src/sys/termios.rs')
-rw-r--r--src/sys/termios.rs61
1 files changed, 60 insertions, 1 deletions
diff --git a/src/sys/termios.rs b/src/sys/termios.rs
index 56beca2e..7ef2ca57 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -17,6 +17,7 @@ mod ffi {
// `Termios` contains bitflags which are not considered
// `foreign-function-safe` by the compiler.
#[allow(improper_ctypes)]
+ #[cfg(any(target_os = "macos", target_os = "linux"))]
extern {
pub fn cfgetispeed(termios: *const Termios) -> speed_t;
pub fn cfgetospeed(termios: *const Termios) -> speed_t;
@@ -32,6 +33,62 @@ mod ffi {
pub fn tcsendbreak(fd: c_int, duration: c_int) -> c_int;
}
+ // On Android before 5.0, Bionic directly inline these to ioctl() calls.
+ #[inline]
+ #[cfg(all(target_os = "android", not(target_arch = "mips")))]
+ mod android {
+ use libc::funcs::bsd44::ioctl;
+ use libc::c_int;
+ use super::consts::*;
+
+ const TCGETS: c_int = 0x5401;
+ const TCSBRK: c_int = 0x5409;
+ const TCXONC: c_int = 0x540a;
+ const TCFLSH: c_int = 0x540b;
+ const TCSBRKP: c_int = 0x5425;
+
+ pub unsafe fn cfgetispeed(termios: *const Termios) -> speed_t {
+ ((*termios).c_cflag & CBAUD).bits() as speed_t
+ }
+ pub unsafe fn cfgetospeed(termios: *const Termios) -> speed_t {
+ ((*termios).c_cflag & CBAUD).bits() as speed_t
+ }
+ pub unsafe fn cfsetispeed(termios: *mut Termios, speed: speed_t) -> c_int {
+ (*termios).c_cflag.remove(CBAUD);
+ (*termios).c_cflag.insert(ControlFlags::from_bits_truncate(speed) & CBAUD);
+ 0
+ }
+ pub unsafe fn cfsetospeed(termios: *mut Termios, speed: speed_t) -> c_int {
+ (*termios).c_cflag.remove(CBAUD);
+ (*termios).c_cflag.insert(ControlFlags::from_bits_truncate(speed) & CBAUD);
+ 0
+ }
+ pub unsafe fn tcgetattr(fd: c_int, termios: *mut Termios) -> c_int {
+ ioctl(fd, TCGETS, termios)
+ }
+ pub unsafe fn tcsetattr(fd: c_int,
+ optional_actions: c_int,
+ termios: *const Termios) -> c_int {
+ ioctl(fd, optional_actions, termios)
+ }
+ pub unsafe fn tcdrain(fd: c_int) -> c_int {
+ ioctl(fd, TCSBRK, 1)
+ }
+ pub unsafe fn tcflow(fd: c_int, action: c_int) -> c_int {
+ ioctl(fd, TCXONC, action)
+ }
+ pub unsafe fn tcflush(fd: c_int, action: c_int) -> c_int {
+ ioctl(fd, TCFLSH, action)
+ }
+ pub unsafe fn tcsendbreak(fd: c_int, duration: c_int) -> c_int {
+ ioctl(fd, TCSBRKP, duration)
+ }
+ }
+
+ #[cfg(target_os = "android")]
+ pub use self::android::*;
+
+
#[cfg(target_os = "macos")]
pub mod consts {
use libc::{c_int, c_ulong, c_uchar};
@@ -198,7 +255,7 @@ mod ffi {
}
}
- #[cfg(target_os = "linux")]
+ #[cfg(any(target_os = "linux", target_os = "android"))]
pub mod consts {
use libc::{c_int, c_uint, c_uchar};
@@ -277,6 +334,8 @@ mod ffi {
const HUPCL = 0x00000400,
const CLOCAL = 0x00000800,
const CRTSCTS = 0x80000000,
+ #[cfg(target_os = "android")]
+ const CBAUD = 0o0010017,
}
}