├── .gitignore ├── .travis.yml ├── CONTRIBUTORS ├── Cargo.toml ├── src ├── os │ ├── mod.rs │ ├── openbsd.rs │ ├── netbsd.rs │ ├── dragonfly.rs │ ├── freebsd.rs │ ├── android.rs │ ├── illumos.rs │ ├── solaris.rs │ ├── linux.rs │ └── macos.rs ├── ffi.rs └── lib.rs ├── LICENSE ├── README.md ├── CHANGELOG.md └── CONTRIBUTING.md /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /Cargo.lock 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | cache: cargo 3 | rust: 4 | - 1.13.0 5 | - stable 6 | - beta 7 | - nightly 8 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Aaron Bieber 2 | atomicules 3 | Conrad Kleinespel 4 | David Cuddeback 5 | Greg V 6 | Joshua M. Clulow 7 | Mike Zeller 8 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "termios" 3 | version = "0.3.3" 4 | authors = ["David Cuddeback "] 5 | description = "Safe bindings for the termios library." 6 | license = "MIT" 7 | homepage = "https://github.com/dcuddeback/termios-rs" 8 | repository = "https://github.com/dcuddeback/termios-rs" 9 | documentation = "http://dcuddeback.github.io/termios-rs/termios/" 10 | readme = "README.md" 11 | keywords = ["termios", "tty", "terminal", "posix"] 12 | 13 | [dependencies] 14 | libc = "0.2" 15 | -------------------------------------------------------------------------------- /src/os/mod.rs: -------------------------------------------------------------------------------- 1 | //! OS-specific definitions. 2 | 3 | #[cfg(target_os = "linux")] pub use self::linux as target; 4 | #[cfg(target_os = "android")] pub use self::android as target; 5 | #[cfg(target_os = "macos")] pub use self::macos as target; 6 | #[cfg(target_os = "freebsd")] pub use self::freebsd as target; 7 | #[cfg(target_os = "openbsd")] pub use self::openbsd as target; 8 | #[cfg(target_os = "netbsd")] pub use self::netbsd as target; 9 | #[cfg(target_os = "dragonfly")] pub use self::dragonfly as target; 10 | #[cfg(target_os = "solaris")] pub use self::solaris as target; 11 | #[cfg(target_os = "illumos")] pub use self::illumos as target; 12 | 13 | #[cfg(target_os = "linux")] pub mod linux; 14 | #[cfg(target_os = "android")] pub mod android; 15 | #[cfg(target_os = "macos")] pub mod macos; 16 | #[cfg(target_os = "freebsd")] pub mod freebsd; 17 | #[cfg(target_os = "openbsd")] pub mod openbsd; 18 | #[cfg(target_os = "netbsd")] pub mod netbsd; 19 | #[cfg(target_os = "dragonfly")] pub mod dragonfly; 20 | #[cfg(target_os = "solaris")] pub mod solaris; 21 | #[cfg(target_os = "illumos")] pub mod illumos; 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 David Cuddeback 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /src/ffi.rs: -------------------------------------------------------------------------------- 1 | //! Unsafe FFI bindings. 2 | 3 | use libc::{c_int,pid_t}; 4 | 5 | #[link(name = "c")] 6 | extern "C" { 7 | pub fn tcgetattr(fd: c_int, termios_p: *mut ::os::target::termios) -> c_int; 8 | pub fn tcsetattr(fd: c_int, optional_actions: c_int, termios_p: *const ::os::target::termios) -> c_int; 9 | pub fn tcsendbreak(fd: c_int, duration: c_int) -> c_int; 10 | pub fn tcdrain(fd: c_int) -> c_int; 11 | pub fn tcflush(fd: c_int, queue_selector: c_int) -> c_int; 12 | pub fn tcflow(fd: c_int, action: c_int) -> c_int; 13 | #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] 14 | pub fn cfmakeraw(termios_p: *mut ::os::target::termios); 15 | pub fn cfgetispeed(termios_p: *const ::os::target::termios) -> ::os::target::speed_t; 16 | pub fn cfgetospeed(termios_p: *const ::os::target::termios) -> ::os::target::speed_t; 17 | pub fn cfsetispeed(termios_p: *mut ::os::target::termios, speed: ::os::target::speed_t) -> c_int; 18 | pub fn cfsetospeed(termios_p: *mut ::os::target::termios, speed: ::os::target::speed_t) -> c_int; 19 | #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] 20 | pub fn cfsetspeed(termios_p: *mut ::os::target::termios, speed: ::os::target::speed_t) -> c_int; 21 | pub fn tcgetsid(fd: c_int) -> pid_t; 22 | } 23 | 24 | #[cfg(any(target_os = "solaris", target_os = "illumos"))] 25 | #[no_mangle] 26 | pub unsafe extern "C" fn cfmakeraw(termios: *mut ::os::target::termios) { 27 | use ::os::target::{IMAXBEL, IGNBRK, BRKINT, PARMRK, ISTRIP, INLCR, IGNCR, ICRNL, IXON}; 28 | use ::os::target::{OPOST, ECHO, ECHONL, ICANON, ISIG, IEXTEN, CSIZE, PARENB, CS8}; 29 | use ::os::target::{VMIN, VTIME}; 30 | 31 | // Equivalent of cfmakeraw() in glibc 32 | (*termios).c_iflag &= !(IMAXBEL | IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); 33 | (*termios).c_oflag &= !OPOST; 34 | (*termios).c_lflag &= !(ECHO | ECHONL | ICANON | ISIG | IEXTEN); 35 | (*termios).c_cflag &= !(CSIZE | PARENB); 36 | (*termios).c_cflag |= CS8; 37 | (*termios).c_cc[VMIN] = 1; 38 | (*termios).c_cc[VTIME] = 0; 39 | } 40 | 41 | #[cfg(any(target_os = "solaris", target_os = "illumos"))] 42 | #[no_mangle] 43 | pub unsafe extern "C" fn cfsetspeed(termios_p: *mut ::os::target::termios, speed: ::os::target::speed_t) -> c_int { 44 | match cfsetispeed(termios_p, speed) { 45 | 0 => cfsetospeed(termios_p, speed), 46 | err => err, 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Termios Rust Bindings 2 | 3 | The `termios` crate provides safe bindings for the Rust programming language to the [terminal I/O 4 | interface](http://pubs.opengroup.org/onlinepubs/009695399/basedefs/termios.h.html) implemented by 5 | Unix operating systems. The safe bindings are a small wrapper around the raw C functions, which 6 | converts integer return values to `std::io::Result` to indicate success or failure. 7 | 8 | * [Documentation](http://dcuddeback.github.io/termios-rs/termios/) 9 | 10 | ## Project Status 11 | 12 | This is a very low-maintenance project. The termios API is decades old. This isn't an area that you 13 | should expect to see daily commits, so don't be put off if you don't see commits for several years. 14 | This just means that the project is stable. That's a good thing. :) 15 | 16 | If, however, you see old patches that you'd like to see land, please see 17 | [`CONTRIBUTING.md`](CONTRIBUTING.md) to see how you can help. 18 | 19 | ## Dependencies & Compatibility 20 | 21 | In order to use the `termios` crate, you must have a native `libc` library that implements the 22 | termios API. This should be available on any Unix operating system. This library contains the 23 | termios definitions for the following platforms: 24 | 25 | * Linux (x86_64, armv6l) 26 | * Android (x86) 27 | * OS X (x86_64) 28 | * FreeBSD (amd64) 29 | * OpenBSD (amd64) 30 | * NetBSD (amd64) 31 | * DragonFly BSD (x86_64) 32 | * illumos (x86_64) 33 | 34 | If you're interested in a platform that's not listed here, please see 35 | [`CONTRIBUTING.md`](CONTRIBUTING.md) to see how you can help. 36 | 37 | ## Usage 38 | 39 | Add `termios` as a dependency in `Cargo.toml`: 40 | 41 | ```toml 42 | [dependencies] 43 | termios = "0.3" 44 | ``` 45 | 46 | Import the `termios` crate and any symbols needed from `termios`. You may also need 47 | `std::os::unix::io::RawFd` for file descriptors and `std::io::Result` to propagate errors. 48 | 49 | ```rust 50 | extern crate termios; 51 | 52 | use std::io; 53 | use std::os::unix::io::RawFd; 54 | 55 | use termios::*; 56 | 57 | fn setup_fd(fd: RawFd) -> io::Result<()> { 58 | let mut termios = try!(Termios::from_fd(fd)); 59 | 60 | termios.c_iflag = IGNPAR | IGNBRK; 61 | termios.c_oflag = 0; 62 | termios.c_cflag = CS8 | CREAD | CLOCAL; 63 | termios.c_lflag = 0; 64 | 65 | try!(cfsetspeed(&mut termios, B9600)); 66 | try!(tcsetattr(fd, TCSANOW, &termios)); 67 | try!(tcflush(fd, TCIOFLUSH)); 68 | 69 | Ok(()) 70 | } 71 | ``` 72 | 73 | ## License 74 | 75 | Copyright © 2015 David Cuddeback 76 | 77 | Distributed under the [MIT License](LICENSE). 78 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## 0.3.2 (2020-04-05) 4 | ### Added 5 | * ([#22](https://github.com/dcuddeback/termios-rs/pull/22)) 6 | Added support for NetBSD. 7 | * ([#21](https://github.com/dcuddeback/termios-rs/pull/21)) 8 | Added support for illumos. 9 | 10 | ## 0.3.1 (2018-10-08) 11 | ### Added 12 | * ([#19](https://github.com/dcuddeback/termios-rs/pull/19)) 13 | Added support for Android. 14 | 15 | ### Changed 16 | * Minimum supported version of Rust is now 1.13.0. 17 | 18 | ## 0.3.0 (2017-12-03) 19 | ### Added 20 | * ([#6](https://github.com/dcuddeback/termios-rs/pull/6)) 21 | Added DragonflyBSD support. 22 | 23 | ### Removed 24 | * Removed `TAB3` from top-level export. 25 | 26 | ## 0.2.2 (2016-01-26) 27 | ### Added 28 | * ([#5](https://github.com/dcuddeback/termios-rs/pull/5)) 29 | Added OpenBSD support. 30 | 31 | ## 0.2.1 (2015-11-04) 32 | ### Changed 33 | * Bumped `libc` dependency to v0.2.0. 34 | 35 | ## 0.2.0 (2015-10-15) 36 | ### Added 37 | * ([#3](https://github.com/dcuddeback/termios-rs/pull/3)) 38 | Added FreeBSD support. 39 | 40 | ### Removed 41 | * Removed top-level export for `c_oflag` values that are not supported globally. 42 | 43 | ## 0.1.0 (2015-05-02) 44 | ### Added 45 | * Added safe wrapper for `tcgetsid()`. 46 | * Converted `Termios` to a wrapper struct with `Deref` and `DerefMut` implementations to access the 47 | inner `termios` struct. 48 | * Export target-specific modules as `os::{platform}`. 49 | 50 | ### Changed 51 | * Export target OS module as `os::target` instead of `os`. 52 | 53 | ### Removed 54 | * Removed `Default` implementation for `Termios`. 55 | * Removed `Termios::zeroed()`. 56 | 57 | ### Changed 58 | * Replaced `c_int` with `RawFd`. 59 | 60 | ## 0.0.5 (2015-04-07) 61 | ### Fixed 62 | * ([#2](https://github.com/dcuddeback/termios-rs/pull/2)) 63 | Updated for compatibility with the new Rust beta channel: 64 | - `libc` is now an external crate. 65 | 66 | ## 0.0.4 (2015-04-03) 67 | ### Fixed 68 | * Updated for compatibility with 1.0.0-beta: 69 | - Implementing `Copy` now requires implementing `Clone`. 70 | 71 | ## 0.0.3 (2015-03-29) 72 | ### Changed 73 | * Migrated from `std::old_io` to `std::io`. 74 | 75 | ## 0.0.2 (2015-02-10) 76 | ### Added 77 | * ([#1](https://github.com/dcuddeback/termios-rs/pull/1)) 78 | Implement `PartialEq` and `Eq` for `Termios` struct. 79 | 80 | ### Fixed 81 | * ([#1](https://github.com/dcuddeback/termios-rs/pull/1)) 82 | Updated for compatibility with latest Rust nightly: 83 | - `std::io` renamed to `std::old_io`. 84 | - `Show` renamed to `Debug`. 85 | 86 | ## 0.0.1 (2015-02-01) 87 | ### Addded 88 | * Added Linux support. 89 | * Added OS X support. 90 | * Added safe wrappers for termios API. 91 | -------------------------------------------------------------------------------- /src/os/openbsd.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | 3 | use libc::{c_int,c_uint,c_uchar}; 4 | 5 | pub type cc_t = c_uchar; 6 | pub type speed_t = c_uint; 7 | pub type tcflag_t = c_uint; 8 | 9 | #[derive(Debug,Copy,Clone,Eq,PartialEq)] 10 | #[repr(C)] 11 | pub struct termios { 12 | pub c_iflag: tcflag_t, 13 | pub c_oflag: tcflag_t, 14 | pub c_cflag: tcflag_t, 15 | pub c_lflag: tcflag_t, 16 | pub c_cc: [cc_t; NCCS], 17 | c_ispeed: speed_t, 18 | c_ospeed: speed_t 19 | } 20 | 21 | pub const NCCS: usize = 20; 22 | 23 | // c_cc characters 24 | pub const VEOF: usize = 0; 25 | pub const VEOL: usize = 1; 26 | pub const VEOL2: usize = 2; 27 | pub const VERASE: usize = 3; 28 | pub const VWERASE: usize = 4; 29 | pub const VKILL: usize = 5; 30 | pub const VREPRINT: usize = 6; 31 | pub const VERASE2: usize = 7; 32 | pub const VINTR: usize = 8; 33 | pub const VQUIT: usize = 9; 34 | pub const VSUSP: usize = 10; 35 | pub const VSTART: usize = 12; 36 | pub const VSTOP: usize = 13; 37 | pub const VLNEXT: usize = 14; 38 | pub const VDISCARD: usize = 15; 39 | pub const VMIN: usize = 16; 40 | pub const VTIME: usize = 17; 41 | 42 | // c_iflag bits 43 | pub const IGNBRK: tcflag_t = 0x00000001; 44 | pub const BRKINT: tcflag_t = 0x00000002; 45 | pub const IGNPAR: tcflag_t = 0x00000004; 46 | pub const PARMRK: tcflag_t = 0x00000008; 47 | pub const INPCK: tcflag_t = 0x00000010; 48 | pub const ISTRIP: tcflag_t = 0x00000020; 49 | pub const INLCR: tcflag_t = 0x00000040; 50 | pub const IGNCR: tcflag_t = 0x00000080; 51 | pub const ICRNL: tcflag_t = 0x00000100; 52 | pub const IXON: tcflag_t = 0x00000200; 53 | pub const IXOFF: tcflag_t = 0x00000400; 54 | pub const IXANY: tcflag_t = 0x00000800; 55 | pub const IMAXBEL: tcflag_t = 0x00002000; 56 | 57 | // c_oflag bits 58 | pub const OPOST: tcflag_t = 0x00000001; 59 | pub const ONLCR: tcflag_t = 0x00000002; 60 | pub const TAB3: tcflag_t = 0x00000004; 61 | pub const OXTABS: tcflag_t = TAB3; 62 | pub const ONOEOT: tcflag_t = 0x00000008; 63 | pub const OCRNL: tcflag_t = 0x00000010; 64 | pub const ONOCR: tcflag_t = 0x00000040; 65 | pub const ONLRET: tcflag_t = 0x00000080; 66 | 67 | // c_cflag bits 68 | pub const CIGNORE: tcflag_t = 0x00000001; 69 | pub const CSIZE: tcflag_t = 0x00000300; 70 | pub const CS5: tcflag_t = 0x00000000; 71 | pub const CS6: tcflag_t = 0x00000100; 72 | pub const CS7: tcflag_t = 0x00000200; 73 | pub const CS8: tcflag_t = 0x00000300; 74 | pub const CSTOPB: tcflag_t = 0x00000400; 75 | pub const CREAD: tcflag_t = 0x00000800; 76 | pub const PARENB: tcflag_t = 0x00001000; 77 | pub const PARODD: tcflag_t = 0x00002000; 78 | pub const HUPCL: tcflag_t = 0x00004000; 79 | pub const CLOCAL: tcflag_t = 0x00008000; 80 | pub const CRTSCTS: tcflag_t = 0x00010000; 81 | pub const CRTS_IFLOW: tcflag_t = CRTSCTS; 82 | pub const CCTS_OFLOW: tcflag_t = CRTSCTS; 83 | pub const MDMBUF: tcflag_t = 0x00100000; 84 | 85 | // c_lflag bits 86 | pub const ECHOKE: tcflag_t = 0x00000001; 87 | pub const ECHOE: tcflag_t = 0x00000002; 88 | pub const ECHOK: tcflag_t = 0x00000004; 89 | pub const ECHO: tcflag_t = 0x00000008; 90 | pub const ECHONL: tcflag_t = 0x00000010; 91 | pub const ECHOPRT: tcflag_t = 0x00000020; 92 | pub const ECHOCTL: tcflag_t = 0x00000040; 93 | pub const ISIG: tcflag_t = 0x00000080; 94 | pub const ICANON: tcflag_t = 0x00000100; 95 | pub const ALTWERASE: tcflag_t = 0x00000200; 96 | pub const IEXTEN: tcflag_t = 0x00000400; 97 | pub const EXTPROC: tcflag_t = 0x00000800; 98 | pub const TOSTOP: tcflag_t = 0x00400000; 99 | pub const FLUSHO: tcflag_t = 0x00800000; 100 | pub const NOKERNINFO: tcflag_t = 0x02000000; 101 | pub const PENDIN: tcflag_t = 0x20000000; 102 | pub const NOFLSH: tcflag_t = 0x80000000; 103 | 104 | // baud rates 105 | pub const B0: speed_t = 0; 106 | pub const B50: speed_t = 50; 107 | pub const B75: speed_t = 75; 108 | pub const B110: speed_t = 110; 109 | pub const B134: speed_t = 134; 110 | pub const B150: speed_t = 150; 111 | pub const B200: speed_t = 200; 112 | pub const B300: speed_t = 300; 113 | pub const B600: speed_t = 600; 114 | pub const B1200: speed_t = 1200; 115 | pub const B1800: speed_t = 1800; 116 | pub const B2400: speed_t = 2400; 117 | pub const B4800: speed_t = 4800; 118 | pub const B9600: speed_t = 9600; 119 | pub const B19200: speed_t = 19200; 120 | pub const B38400: speed_t = 38400; 121 | pub const B7200: speed_t = 7200; 122 | pub const B14400: speed_t = 14400; 123 | pub const B28800: speed_t = 28800; 124 | pub const B57600: speed_t = 57600; 125 | pub const B76800: speed_t = 76800; 126 | pub const B115200: speed_t = 115200; 127 | pub const B230400: speed_t = 230400; 128 | pub const EXTA: speed_t = 19200; 129 | pub const EXTB: speed_t = 38400; 130 | 131 | // tcflow() 132 | pub const TCOOFF: c_int = 1; 133 | pub const TCOON: c_int = 2; 134 | pub const TCIOFF: c_int = 3; 135 | pub const TCION: c_int = 4; 136 | 137 | // tcflush() 138 | pub const TCIFLUSH: c_int = 1; 139 | pub const TCOFLUSH: c_int = 2; 140 | pub const TCIOFLUSH: c_int = 3; 141 | 142 | // tcsetattr() 143 | pub const TCSANOW: c_int = 0; 144 | pub const TCSADRAIN: c_int = 1; 145 | pub const TCSAFLUSH: c_int = 2; 146 | pub const TCSASOFT: c_int = 0x10; 147 | -------------------------------------------------------------------------------- /src/os/netbsd.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | 3 | use libc::{c_int,c_uint,c_uchar}; 4 | 5 | pub type cc_t = c_uchar; 6 | pub type speed_t = c_uint; 7 | pub type tcflag_t = c_uint; 8 | 9 | #[derive(Debug,Copy,Clone,Eq,PartialEq)] 10 | #[repr(C)] 11 | pub struct termios { 12 | pub c_iflag: tcflag_t, 13 | pub c_oflag: tcflag_t, 14 | pub c_cflag: tcflag_t, 15 | pub c_lflag: tcflag_t, 16 | pub c_cc: [cc_t; NCCS], 17 | c_ispeed: c_int, 18 | c_ospeed: c_int 19 | } 20 | 21 | pub const NCCS: usize = 20; 22 | 23 | // c_cc characters 24 | pub const VEOF: usize = 0; 25 | pub const VEOL: usize = 1; 26 | pub const VEOL2: usize = 2; 27 | pub const VERASE: usize = 3; 28 | pub const VWERASE: usize = 4; 29 | pub const VKILL: usize = 5; 30 | pub const VREPRINT: usize = 6; 31 | pub const VINTR: usize = 8; 32 | pub const VQUIT: usize = 9; 33 | pub const VSUSP: usize = 10; 34 | pub const VSTART: usize = 12; 35 | pub const VSTOP: usize = 13; 36 | pub const VLNEXT: usize = 14; 37 | pub const VDISCARD: usize = 15; 38 | pub const VMIN: usize = 16; 39 | pub const VTIME: usize = 17; 40 | pub const VSTATUS: usize = 18; 41 | 42 | // c_iflag bits 43 | pub const IGNBRK: tcflag_t = 0x00000001; 44 | pub const BRKINT: tcflag_t = 0x00000002; 45 | pub const IGNPAR: tcflag_t = 0x00000004; 46 | pub const PARMRK: tcflag_t = 0x00000008; 47 | pub const INPCK: tcflag_t = 0x00000010; 48 | pub const ISTRIP: tcflag_t = 0x00000020; 49 | pub const INLCR: tcflag_t = 0x00000040; 50 | pub const IGNCR: tcflag_t = 0x00000080; 51 | pub const ICRNL: tcflag_t = 0x00000100; 52 | pub const IXON: tcflag_t = 0x00000200; 53 | pub const IXOFF: tcflag_t = 0x00000400; 54 | pub const IXANY: tcflag_t = 0x00000800; 55 | pub const IMAXBEL: tcflag_t = 0x00002000; 56 | 57 | // c_oflag bits 58 | pub const OPOST: tcflag_t = 0x00000001; 59 | pub const ONLCR: tcflag_t = 0x00000002; 60 | pub const OXTABS: tcflag_t = 0x00000004; 61 | pub const ONOEOT: tcflag_t = 0x00000008; 62 | pub const OCRNL: tcflag_t = 0x00000010; 63 | pub const ONOCR: tcflag_t = 0x00000020; 64 | pub const ONLRET: tcflag_t = 0x00000040; 65 | 66 | // c_cflag bits 67 | pub const CIGNORE: tcflag_t = 0x00000001; 68 | pub const CSIZE: tcflag_t = 0x00000300; 69 | pub const CS5: tcflag_t = 0x00000000; 70 | pub const CS6: tcflag_t = 0x00000100; 71 | pub const CS7: tcflag_t = 0x00000200; 72 | pub const CS8: tcflag_t = 0x00000300; 73 | pub const CSTOPB: tcflag_t = 0x00000400; 74 | pub const CREAD: tcflag_t = 0x00000800; 75 | pub const PARENB: tcflag_t = 0x00001000; 76 | pub const PARODD: tcflag_t = 0x00002000; 77 | pub const HUPCL: tcflag_t = 0x00004000; 78 | pub const CLOCAL: tcflag_t = 0x00008000; 79 | pub const CRTSCTS: tcflag_t = 0x00010000; 80 | pub const CRTS_IFLOW: tcflag_t = CRTSCTS; 81 | pub const CCTS_OFLOW: tcflag_t = CRTSCTS; 82 | pub const CDTRCTS: tcflag_t = 0x00020000; 83 | pub const MDMBUF: tcflag_t = 0x00100000; 84 | pub const CHWFLOW: tcflag_t = MDMBUF|CRTSCTS|CDTRCTS; 85 | 86 | // c_lflag bits 87 | pub const ECHOKE: tcflag_t = 0x00000001; 88 | pub const ECHOE: tcflag_t = 0x00000002; 89 | pub const ECHOK: tcflag_t = 0x00000004; 90 | pub const ECHO: tcflag_t = 0x00000008; 91 | pub const ECHONL: tcflag_t = 0x00000010; 92 | pub const ECHOPRT: tcflag_t = 0x00000020; 93 | pub const ECHOCTL: tcflag_t = 0x00000040; 94 | pub const ISIG: tcflag_t = 0x00000080; 95 | pub const ICANON: tcflag_t = 0x00000100; 96 | pub const ALTWERASE: tcflag_t = 0x00000200; 97 | pub const IEXTEN: tcflag_t = 0x00000400; 98 | pub const EXTPROC: tcflag_t = 0x00000800; 99 | pub const TOSTOP: tcflag_t = 0x00400000; 100 | pub const FLUSHO: tcflag_t = 0x00800000; 101 | pub const NOKERNINFO: tcflag_t = 0x02000000; 102 | pub const PENDIN: tcflag_t = 0x20000000; 103 | pub const NOFLSH: tcflag_t = 0x80000000; 104 | 105 | // baud rates 106 | pub const B0: speed_t = 0; 107 | pub const B50: speed_t = 50; 108 | pub const B75: speed_t = 75; 109 | pub const B110: speed_t = 110; 110 | pub const B134: speed_t = 134; 111 | pub const B150: speed_t = 150; 112 | pub const B200: speed_t = 200; 113 | pub const B300: speed_t = 300; 114 | pub const B600: speed_t = 600; 115 | pub const B1200: speed_t = 1200; 116 | pub const B1800: speed_t = 1800; 117 | pub const B2400: speed_t = 2400; 118 | pub const B4800: speed_t = 4800; 119 | pub const B9600: speed_t = 9600; 120 | pub const B19200: speed_t = 19200; 121 | pub const B38400: speed_t = 38400; 122 | pub const B7200: speed_t = 7200; 123 | pub const B14400: speed_t = 14400; 124 | pub const B28800: speed_t = 28800; 125 | pub const B57600: speed_t = 57600; 126 | pub const B76800: speed_t = 76800; 127 | pub const B115200: speed_t = 115200; 128 | pub const B230400: speed_t = 230400; 129 | pub const B460800: speed_t = 460800; 130 | pub const B921600: speed_t = 921600; 131 | pub const EXTA: speed_t = 19200; 132 | pub const EXTB: speed_t = 38400; 133 | 134 | // tcflow() 135 | pub const TCOOFF: c_int = 1; 136 | pub const TCOON: c_int = 2; 137 | pub const TCIOFF: c_int = 3; 138 | pub const TCION: c_int = 4; 139 | 140 | // tcflush() 141 | pub const TCIFLUSH: c_int = 1; 142 | pub const TCOFLUSH: c_int = 2; 143 | pub const TCIOFLUSH: c_int = 3; 144 | 145 | // tcsetattr() 146 | pub const TCSANOW: c_int = 0; 147 | pub const TCSADRAIN: c_int = 1; 148 | pub const TCSAFLUSH: c_int = 2; 149 | pub const TCSASOFT: c_int = 0x10; 150 | -------------------------------------------------------------------------------- /src/os/dragonfly.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | 3 | use libc::{c_int,c_uint,c_uchar}; 4 | 5 | pub type cc_t = c_uchar; 6 | pub type speed_t = c_uint; 7 | pub type tcflag_t = c_uint; 8 | 9 | #[derive(Debug,Copy,Clone,Eq,PartialEq)] 10 | #[repr(C)] 11 | pub struct termios { 12 | pub c_iflag: tcflag_t, 13 | pub c_oflag: tcflag_t, 14 | pub c_cflag: tcflag_t, 15 | pub c_lflag: tcflag_t, 16 | pub c_cc: [cc_t; NCCS], 17 | c_ispeed: speed_t, 18 | c_ospeed: speed_t 19 | } 20 | 21 | pub const NCCS: usize = 20; 22 | 23 | // c_cc characters 24 | pub const VEOF: usize = 0; 25 | pub const VEOL: usize = 1; 26 | pub const VEOL2: usize = 2; 27 | pub const VERASE: usize = 3; 28 | pub const VWERASE: usize = 4; 29 | pub const VKILL: usize = 5; 30 | pub const VREPRINT: usize = 6; 31 | pub const VERASE2: usize = 7; 32 | pub const VINTR: usize = 8; 33 | pub const VQUIT: usize = 9; 34 | pub const VSUSP: usize = 10; 35 | pub const VDSUSP: usize = 11; 36 | pub const VSTART: usize = 12; 37 | pub const VSTOP: usize = 13; 38 | pub const VLNEXT: usize = 14; 39 | pub const VDISCARD: usize = 15; 40 | pub const VMIN: usize = 16; 41 | pub const VTIME: usize = 17; 42 | pub const VSTATUS: usize = 18; 43 | pub const VCHECKPT: usize = 19; 44 | 45 | // c_iflag bits 46 | pub const IGNBRK: tcflag_t = 0x00000001; 47 | pub const BRKINT: tcflag_t = 0x00000002; 48 | pub const IGNPAR: tcflag_t = 0x00000004; 49 | pub const PARMRK: tcflag_t = 0x00000008; 50 | pub const INPCK: tcflag_t = 0x00000010; 51 | pub const ISTRIP: tcflag_t = 0x00000020; 52 | pub const INLCR: tcflag_t = 0x00000040; 53 | pub const IGNCR: tcflag_t = 0x00000080; 54 | pub const ICRNL: tcflag_t = 0x00000100; 55 | pub const IXON: tcflag_t = 0x00000200; 56 | pub const IXOFF: tcflag_t = 0x00000400; 57 | pub const IXANY: tcflag_t = 0x00000800; 58 | pub const IMAXBEL: tcflag_t = 0x00002000; 59 | 60 | // c_oflag bits 61 | pub const OPOST: tcflag_t = 0x00000001; 62 | pub const ONLCR: tcflag_t = 0x00000002; 63 | pub const OXTABS: tcflag_t = 0x00000004; 64 | pub const ONOEOT: tcflag_t = 0x00000008; 65 | pub const OCRNL: tcflag_t = 0x00000010; 66 | pub const ONOCR: tcflag_t = 0x00000020; 67 | pub const ONLRET: tcflag_t = 0x00000040; 68 | 69 | // c_cflag bits 70 | pub const CIGNORE: tcflag_t = 0x00000001; 71 | pub const CSIZE: tcflag_t = 0x00000300; 72 | pub const CS5: tcflag_t = 0x00000000; 73 | pub const CS6: tcflag_t = 0x00000100; 74 | pub const CS7: tcflag_t = 0x00000200; 75 | pub const CS8: tcflag_t = 0x00000300; 76 | pub const CSTOPB: tcflag_t = 0x00000400; 77 | pub const CREAD: tcflag_t = 0x00000800; 78 | pub const PARENB: tcflag_t = 0x00001000; 79 | pub const PARODD: tcflag_t = 0x00002000; 80 | pub const HUPCL: tcflag_t = 0x00004000; 81 | pub const CLOCAL: tcflag_t = 0x00008000; 82 | pub const CCTS_OFLOW: tcflag_t = 0x00010000; 83 | pub const CRTSCTS: tcflag_t = CCTS_OFLOW | CRTS_IFLOW; 84 | pub const CRTS_IFLOW: tcflag_t = 0x00020000; 85 | pub const CDTR_IFLOW: tcflag_t = 0x00040000; 86 | pub const CDSR_OFLOW: tcflag_t = 0x00080000; 87 | pub const CCAR_OFLOW: tcflag_t = 0x00100000; 88 | pub const MDMBUF: tcflag_t = 0x00100000; 89 | 90 | // c_lflag bits 91 | pub const ECHOKE: tcflag_t = 0x00000001; 92 | pub const ECHOE: tcflag_t = 0x00000002; 93 | pub const ECHOK: tcflag_t = 0x00000004; 94 | pub const ECHO: tcflag_t = 0x00000008; 95 | pub const ECHONL: tcflag_t = 0x00000010; 96 | pub const ECHOPRT: tcflag_t = 0x00000020; 97 | pub const ECHOCTL: tcflag_t = 0x00000040; 98 | pub const ISIG: tcflag_t = 0x00000080; 99 | pub const ICANON: tcflag_t = 0x00000100; 100 | pub const ALTWERASE: tcflag_t = 0x00000200; 101 | pub const IEXTEN: tcflag_t = 0x00000400; 102 | pub const EXTPROC: tcflag_t = 0x00000800; 103 | pub const TOSTOP: tcflag_t = 0x00400000; 104 | pub const FLUSHO: tcflag_t = 0x00800000; 105 | pub const NOKERNINFO: tcflag_t = 0x02000000; 106 | pub const PENDIN: tcflag_t = 0x20000000; 107 | pub const NOFLSH: tcflag_t = 0x80000000; 108 | 109 | // baud rates 110 | pub const B0: speed_t = 0; 111 | pub const B50: speed_t = 50; 112 | pub const B75: speed_t = 75; 113 | pub const B110: speed_t = 110; 114 | pub const B134: speed_t = 134; 115 | pub const B150: speed_t = 150; 116 | pub const B200: speed_t = 200; 117 | pub const B300: speed_t = 300; 118 | pub const B600: speed_t = 600; 119 | pub const B1200: speed_t = 1200; 120 | pub const B1800: speed_t = 1800; 121 | pub const B2400: speed_t = 2400; 122 | pub const B4800: speed_t = 4800; 123 | pub const B9600: speed_t = 9600; 124 | pub const B19200: speed_t = 19200; 125 | pub const B38400: speed_t = 38400; 126 | pub const B7200: speed_t = 7200; 127 | pub const B14400: speed_t = 14400; 128 | pub const B28800: speed_t = 28800; 129 | pub const B57600: speed_t = 57600; 130 | pub const B76800: speed_t = 76800; 131 | pub const B115200: speed_t = 115200; 132 | pub const B230400: speed_t = 230400; 133 | pub const EXTA: speed_t = 19200; 134 | pub const EXTB: speed_t = 38400; 135 | 136 | // tcsetattr() 137 | pub const TCSANOW: c_int = 0; 138 | pub const TCSADRAIN: c_int = 1; 139 | pub const TCSAFLUSH: c_int = 2; 140 | pub const TCSASOFT: c_int = 0x10; 141 | 142 | // tcflush() 143 | pub const TCIFLUSH: c_int = 1; 144 | pub const TCOFLUSH: c_int = 2; 145 | pub const TCIOFLUSH: c_int = 3; 146 | 147 | // tcflow() 148 | pub const TCOOFF: c_int = 1; 149 | pub const TCOON: c_int = 2; 150 | pub const TCIOFF: c_int = 3; 151 | pub const TCION: c_int = 4; 152 | -------------------------------------------------------------------------------- /src/os/freebsd.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | 3 | use libc::{c_int,c_uint,c_uchar}; 4 | 5 | pub type cc_t = c_uchar; 6 | pub type speed_t = c_uint; 7 | pub type tcflag_t = c_uint; 8 | 9 | #[derive(Debug,Copy,Clone,Eq,PartialEq)] 10 | #[repr(C)] 11 | pub struct termios { 12 | pub c_iflag: tcflag_t, 13 | pub c_oflag: tcflag_t, 14 | pub c_cflag: tcflag_t, 15 | pub c_lflag: tcflag_t, 16 | pub c_cc: [cc_t; NCCS], 17 | c_ispeed: speed_t, 18 | c_ospeed: speed_t 19 | } 20 | 21 | pub const NCCS: usize = 20; 22 | 23 | // c_cc characters 24 | pub const VEOF: usize = 0; 25 | pub const VEOL: usize = 1; 26 | pub const VEOL2: usize = 2; 27 | pub const VERASE: usize = 3; 28 | pub const VWERASE: usize = 4; 29 | pub const VKILL: usize = 5; 30 | pub const VREPRINT: usize = 6; 31 | pub const VERASE2: usize = 7; 32 | pub const VINTR: usize = 8; 33 | pub const VQUIT: usize = 9; 34 | pub const VSUSP: usize = 10; 35 | pub const VDSUSP: usize = 11; 36 | pub const VSTART: usize = 12; 37 | pub const VSTOP: usize = 13; 38 | pub const VLNEXT: usize = 14; 39 | pub const VDISCARD: usize = 15; 40 | pub const VMIN: usize = 16; 41 | pub const VTIME: usize = 17; 42 | pub const VSTATUS: usize = 18; 43 | 44 | // c_iflag bits 45 | pub const IGNBRK: tcflag_t = 0x00000001; 46 | pub const BRKINT: tcflag_t = 0x00000002; 47 | pub const IGNPAR: tcflag_t = 0x00000004; 48 | pub const PARMRK: tcflag_t = 0x00000008; 49 | pub const INPCK: tcflag_t = 0x00000010; 50 | pub const ISTRIP: tcflag_t = 0x00000020; 51 | pub const INLCR: tcflag_t = 0x00000040; 52 | pub const IGNCR: tcflag_t = 0x00000080; 53 | pub const ICRNL: tcflag_t = 0x00000100; 54 | pub const IXON: tcflag_t = 0x00000200; 55 | pub const IXOFF: tcflag_t = 0x00000400; 56 | pub const IXANY: tcflag_t = 0x00000800; 57 | pub const IMAXBEL: tcflag_t = 0x00002000; 58 | 59 | // c_oflag bits 60 | pub const OPOST: tcflag_t = 0x00000001; 61 | pub const ONLCR: tcflag_t = 0x00000002; 62 | pub const TABDLY: tcflag_t = 0x00000004; 63 | pub const TAB0: tcflag_t = 0x00000000; 64 | pub const TAB3: tcflag_t = 0x00000004; 65 | pub const OXTABS: tcflag_t = TAB3; 66 | pub const ONOEOT: tcflag_t = 0x00000008; 67 | pub const OCRNL: tcflag_t = 0x00000010; 68 | pub const ONOCR: tcflag_t = 0x00000020; 69 | pub const ONLRET: tcflag_t = 0x00000040; 70 | 71 | // c_cflag bits 72 | pub const CIGNORE: tcflag_t = 0x00000001; 73 | pub const CSIZE: tcflag_t = 0x00000300; 74 | pub const CS5: tcflag_t = 0x00000000; 75 | pub const CS6: tcflag_t = 0x00000100; 76 | pub const CS7: tcflag_t = 0x00000200; 77 | pub const CS8: tcflag_t = 0x00000300; 78 | pub const CSTOPB: tcflag_t = 0x00000400; 79 | pub const CREAD: tcflag_t = 0x00000800; 80 | pub const PARENB: tcflag_t = 0x00001000; 81 | pub const PARODD: tcflag_t = 0x00002000; 82 | pub const HUPCL: tcflag_t = 0x00004000; 83 | pub const CLOCAL: tcflag_t = 0x00008000; 84 | pub const CCTS_OFLOW: tcflag_t = 0x00010000; 85 | pub const CRTSCTS: tcflag_t = CCTS_OFLOW | CRTS_IFLOW; 86 | pub const CRTS_IFLOW: tcflag_t = 0x00020000; 87 | pub const CDTR_IFLOW: tcflag_t = 0x00040000; 88 | pub const CDSR_OFLOW: tcflag_t = 0x00080000; 89 | pub const CCAR_OFLOW: tcflag_t = 0x00100000; 90 | pub const MDMBUF: tcflag_t = CCAR_OFLOW; 91 | 92 | // c_lflag bits 93 | pub const ECHOKE: tcflag_t = 0x00000001; 94 | pub const ECHOE: tcflag_t = 0x00000002; 95 | pub const ECHOK: tcflag_t = 0x00000004; 96 | pub const ECHO: tcflag_t = 0x00000008; 97 | pub const ECHONL: tcflag_t = 0x00000010; 98 | pub const ECHOPRT: tcflag_t = 0x00000020; 99 | pub const ECHOCTL: tcflag_t = 0x00000040; 100 | pub const ISIG: tcflag_t = 0x00000080; 101 | pub const ICANON: tcflag_t = 0x00000100; 102 | pub const ALTWERASE: tcflag_t = 0x00000200; 103 | pub const IEXTEN: tcflag_t = 0x00000400; 104 | pub const EXTPROC: tcflag_t = 0x00000800; 105 | pub const TOSTOP: tcflag_t = 0x00400000; 106 | pub const FLUSHO: tcflag_t = 0x00800000; 107 | pub const NOKERNINFO: tcflag_t = 0x02000000; 108 | pub const PENDIN: tcflag_t = 0x20000000; 109 | pub const NOFLSH: tcflag_t = 0x80000000; 110 | 111 | // baud rates 112 | pub const B0: speed_t = 0; 113 | pub const B50: speed_t = 50; 114 | pub const B75: speed_t = 75; 115 | pub const B110: speed_t = 110; 116 | pub const B134: speed_t = 134; 117 | pub const B150: speed_t = 150; 118 | pub const B200: speed_t = 200; 119 | pub const B300: speed_t = 300; 120 | pub const B600: speed_t = 600; 121 | pub const B1200: speed_t = 1200; 122 | pub const B1800: speed_t = 1800; 123 | pub const B2400: speed_t = 2400; 124 | pub const B4800: speed_t = 4800; 125 | pub const B9600: speed_t = 9600; 126 | pub const B19200: speed_t = 19200; 127 | pub const B38400: speed_t = 38400; 128 | pub const B7200: speed_t = 7200; 129 | pub const B14400: speed_t = 14400; 130 | pub const B28800: speed_t = 28800; 131 | pub const B57600: speed_t = 57600; 132 | pub const B76800: speed_t = 76800; 133 | pub const B115200: speed_t = 115200; 134 | pub const B230400: speed_t = 230400; 135 | pub const B460800: speed_t = 460800; 136 | pub const B921600: speed_t = 921600; 137 | pub const EXTA: speed_t = 19200; 138 | pub const EXTB: speed_t = 38400; 139 | 140 | // tcflow() 141 | pub const TCOOFF: c_int = 1; 142 | pub const TCOON: c_int = 2; 143 | pub const TCIOFF: c_int = 3; 144 | pub const TCION: c_int = 4; 145 | 146 | // tcflush() 147 | pub const TCIFLUSH: c_int = 1; 148 | pub const TCOFLUSH: c_int = 2; 149 | pub const TCIOFLUSH: c_int = 3; 150 | 151 | // tcsetattr() 152 | pub const TCSANOW: c_int = 0; 153 | pub const TCSADRAIN: c_int = 1; 154 | pub const TCSAFLUSH: c_int = 2; 155 | pub const TCSASOFT: c_int = 0x10; 156 | -------------------------------------------------------------------------------- /src/os/android.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | 3 | use libc::{c_int,c_uint,c_uchar}; 4 | 5 | pub type cc_t = c_uchar; 6 | pub type speed_t = c_uint; 7 | pub type tcflag_t = c_uint; 8 | 9 | #[derive(Debug,Copy,Clone,Eq,PartialEq)] 10 | #[repr(C)] 11 | pub struct termios { 12 | pub c_iflag: tcflag_t, 13 | pub c_oflag: tcflag_t, 14 | pub c_cflag: tcflag_t, 15 | pub c_lflag: tcflag_t, 16 | c_line: cc_t, 17 | pub c_cc: [cc_t; NCCS] 18 | } 19 | 20 | pub const NCCS: usize = 19; 21 | 22 | // c_cc characters 23 | pub const VINTR: usize = 0; 24 | pub const VQUIT: usize = 1; 25 | pub const VERASE: usize = 2; 26 | pub const VKILL: usize = 3; 27 | pub const VEOF: usize = 4; 28 | pub const VTIME: usize = 5; 29 | pub const VMIN: usize = 6; 30 | pub const VSWTC: usize = 7; 31 | pub const VSTART: usize = 8; 32 | pub const VSTOP: usize = 9; 33 | pub const VSUSP: usize = 10; 34 | pub const VEOL: usize = 11; 35 | pub const VREPRINT: usize = 12; 36 | pub const VDISCARD: usize = 13; 37 | pub const VWERASE: usize = 14; 38 | pub const VLNEXT: usize = 15; 39 | pub const VEOL2: usize = 16; 40 | 41 | // c_iflag bits 42 | pub const IGNBRK: tcflag_t = 0o000001; 43 | pub const BRKINT: tcflag_t = 0o000002; 44 | pub const IGNPAR: tcflag_t = 0o000004; 45 | pub const PARMRK: tcflag_t = 0o000010; 46 | pub const INPCK: tcflag_t = 0o000020; 47 | pub const ISTRIP: tcflag_t = 0o000040; 48 | pub const INLCR: tcflag_t = 0o000100; 49 | pub const IGNCR: tcflag_t = 0o000200; 50 | pub const ICRNL: tcflag_t = 0o000400; 51 | pub const IUCLC: tcflag_t = 0o001000; 52 | pub const IXON: tcflag_t = 0o002000; 53 | pub const IXANY: tcflag_t = 0o004000; 54 | pub const IXOFF: tcflag_t = 0o010000; 55 | pub const IMAXBEL: tcflag_t = 0o020000; 56 | pub const IUTF8: tcflag_t = 0o040000; 57 | 58 | // c_oflag bits 59 | pub const OPOST: tcflag_t = 0o000001; 60 | pub const OLCUC: tcflag_t = 0o000002; 61 | pub const ONLCR: tcflag_t = 0o000004; 62 | pub const OCRNL: tcflag_t = 0o000010; 63 | pub const ONOCR: tcflag_t = 0o000020; 64 | pub const ONLRET: tcflag_t = 0o000040; 65 | pub const OFILL: tcflag_t = 0o000100; 66 | pub const OFDEL: tcflag_t = 0o000200; 67 | pub const NLDLY: tcflag_t = 0o000400; 68 | pub const NL0: tcflag_t = 0o000000; 69 | pub const NL1: tcflag_t = 0o000400; 70 | pub const CRDLY: tcflag_t = 0o003000; 71 | pub const CR0: tcflag_t = 0o000000; 72 | pub const CR1: tcflag_t = 0o001000; 73 | pub const CR2: tcflag_t = 0o002000; 74 | pub const CR3: tcflag_t = 0o003000; 75 | pub const TABDLY: tcflag_t = 0o014000; 76 | pub const TAB0: tcflag_t = 0o000000; 77 | pub const TAB1: tcflag_t = 0o004000; 78 | pub const TAB2: tcflag_t = 0o010000; 79 | pub const TAB3: tcflag_t = 0o014000; 80 | pub const BSDLY: tcflag_t = 0o020000; 81 | pub const BS0: tcflag_t = 0o000000; 82 | pub const BS1: tcflag_t = 0o020000; 83 | pub const FFDLY: tcflag_t = 0o100000; 84 | pub const FF0: tcflag_t = 0o000000; 85 | pub const FF1: tcflag_t = 0o100000; 86 | pub const VTDLY: tcflag_t = 0o040000; 87 | pub const VT0: tcflag_t = 0o000000; 88 | pub const VT1: tcflag_t = 0o040000; 89 | pub const XTABS: tcflag_t = 0o014000; 90 | 91 | // c_cflag bits 92 | pub const CBAUD: tcflag_t = 0o010017; 93 | pub const CSIZE: tcflag_t = 0o000060; 94 | pub const CS5: tcflag_t = 0o000000; 95 | pub const CS6: tcflag_t = 0o000020; 96 | pub const CS7: tcflag_t = 0o000040; 97 | pub const CS8: tcflag_t = 0o000060; 98 | pub const CSTOPB: tcflag_t = 0o000100; 99 | pub const CREAD: tcflag_t = 0o000200; 100 | pub const PARENB: tcflag_t = 0o000400; 101 | pub const PARODD: tcflag_t = 0o001000; 102 | pub const HUPCL: tcflag_t = 0o002000; 103 | pub const CLOCAL: tcflag_t = 0o004000; 104 | pub const CBAUDEX: tcflag_t = 0o010000; 105 | pub const CIBAUD: tcflag_t = 0o02003600000; 106 | pub const CMSPAR: tcflag_t = 0o10000000000; 107 | pub const CRTSCTS: tcflag_t = 0o20000000000; 108 | 109 | // c_lflag bits 110 | pub const ISIG: tcflag_t = 0o000001; 111 | pub const ICANON: tcflag_t = 0o000002; 112 | pub const XCASE: tcflag_t = 0o000004; 113 | pub const ECHO: tcflag_t = 0o000010; 114 | pub const ECHOE: tcflag_t = 0o000020; 115 | pub const ECHOK: tcflag_t = 0o000040; 116 | pub const ECHONL: tcflag_t = 0o000100; 117 | pub const NOFLSH: tcflag_t = 0o000200; 118 | pub const TOSTOP: tcflag_t = 0o000400; 119 | pub const ECHOCTL: tcflag_t = 0o001000; 120 | pub const ECHOPRT: tcflag_t = 0o002000; 121 | pub const ECHOKE: tcflag_t = 0o004000; 122 | pub const FLUSHO: tcflag_t = 0o010000; 123 | pub const PENDIN: tcflag_t = 0o040000; 124 | pub const IEXTEN: tcflag_t = 0o100000; 125 | pub const EXTPROC: tcflag_t = 0o200000; 126 | 127 | // baud rates 128 | pub const B0: speed_t = 0o000000; 129 | pub const B50: speed_t = 0o000001; 130 | pub const B75: speed_t = 0o000002; 131 | pub const B110: speed_t = 0o000003; 132 | pub const B134: speed_t = 0o000004; 133 | pub const B150: speed_t = 0o000005; 134 | pub const B200: speed_t = 0o000006; 135 | pub const B300: speed_t = 0o000007; 136 | pub const B600: speed_t = 0o000010; 137 | pub const B1200: speed_t = 0o000011; 138 | pub const B1800: speed_t = 0o000012; 139 | pub const B2400: speed_t = 0o000013; 140 | pub const B4800: speed_t = 0o000014; 141 | pub const B9600: speed_t = 0o000015; 142 | pub const B19200: speed_t = 0o000016; 143 | pub const B38400: speed_t = 0o000017; 144 | pub const EXTA: speed_t = B19200; 145 | pub const EXTB: speed_t = B38400; 146 | pub const B57600: speed_t = 0o010001; 147 | pub const B115200: speed_t = 0o010002; 148 | pub const B230400: speed_t = 0o010003; 149 | pub const B460800: speed_t = 0o010004; 150 | pub const B500000: speed_t = 0o010005; 151 | pub const B576000: speed_t = 0o010006; 152 | pub const B921600: speed_t = 0o010007; 153 | pub const B1000000: speed_t = 0o010010; 154 | pub const B1152000: speed_t = 0o010011; 155 | pub const B1500000: speed_t = 0o010012; 156 | pub const B2000000: speed_t = 0o010013; 157 | pub const B2500000: speed_t = 0o010014; 158 | pub const B3000000: speed_t = 0o010015; 159 | pub const B3500000: speed_t = 0o010016; 160 | pub const B4000000: speed_t = 0o010017; 161 | 162 | // tcflow() 163 | pub const TCOOFF: c_int = 0; 164 | pub const TCOON: c_int = 1; 165 | pub const TCIOFF: c_int = 2; 166 | pub const TCION: c_int = 3; 167 | 168 | // tcflush() 169 | pub const TCIFLUSH: c_int = 0; 170 | pub const TCOFLUSH: c_int = 1; 171 | pub const TCIOFLUSH: c_int = 2; 172 | 173 | // tcsetattr() 174 | pub const TCSANOW: c_int = 0; 175 | pub const TCSADRAIN: c_int = 1; 176 | pub const TCSAFLUSH: c_int = 2; 177 | -------------------------------------------------------------------------------- /src/os/illumos.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | 3 | use libc::{c_int,c_uint,c_uchar}; 4 | 5 | pub type cc_t = c_uchar; 6 | pub type speed_t = c_uint; 7 | pub type tcflag_t = c_uint; 8 | 9 | #[derive(Debug,Copy,Clone,Eq,PartialEq)] 10 | #[repr(C)] 11 | pub struct termios { 12 | pub c_iflag: tcflag_t, 13 | pub c_oflag: tcflag_t, 14 | pub c_cflag: tcflag_t, 15 | pub c_lflag: tcflag_t, 16 | pub c_cc: [cc_t; NCCS] 17 | } 18 | 19 | pub const NCCS: usize = 19; 20 | 21 | // c_cc characters 22 | pub const VINTR: usize = 0; 23 | pub const VQUIT: usize = 1; 24 | pub const VERASE: usize = 2; 25 | pub const VKILL: usize = 3; 26 | pub const VEOF: usize = 4; 27 | pub const VEOL: usize = 5; 28 | pub const VEOL2: usize = 6; 29 | pub const VMIN: usize = 4; 30 | pub const VTIME: usize = 5; 31 | pub const VSWTCH: usize = 7; 32 | pub const VSTART: usize = 8; 33 | pub const VSTOP: usize = 9; 34 | pub const VSUSP: usize = 10; 35 | pub const VDSUSP: usize = 11; 36 | pub const VREPRINT: usize = 12; 37 | pub const VDISCARD: usize = 13; 38 | pub const VWERASE: usize = 14; 39 | pub const VLNEXT: usize = 15; 40 | pub const VSTATUS: usize = 16; 41 | pub const VERASE2: usize = 17; 42 | 43 | // c_iflag bits 44 | pub const IGNBRK: tcflag_t = 0o000001; 45 | pub const BRKINT: tcflag_t = 0o000002; 46 | pub const IGNPAR: tcflag_t = 0o000004; 47 | pub const PARMRK: tcflag_t = 0o000010; 48 | pub const INPCK: tcflag_t = 0o000020; 49 | pub const ISTRIP: tcflag_t = 0o000040; 50 | pub const INLCR: tcflag_t = 0o000100; 51 | pub const IGNCR: tcflag_t = 0o000200; 52 | pub const ICRNL: tcflag_t = 0o000400; 53 | pub const IUCLC: tcflag_t = 0o001000; 54 | pub const IXON: tcflag_t = 0o002000; 55 | pub const IXANY: tcflag_t = 0o004000; 56 | pub const IXOFF: tcflag_t = 0o010000; 57 | pub const IMAXBEL: tcflag_t = 0o020000; 58 | pub const DOSMODE: tcflag_t = 0o100000; 59 | 60 | // c_oflag bits 61 | pub const OPOST: tcflag_t = 0o000001; 62 | pub const OLCUC: tcflag_t = 0o000002; 63 | pub const ONLCR: tcflag_t = 0o000004; 64 | pub const OCRNL: tcflag_t = 0o000010; 65 | pub const ONOCR: tcflag_t = 0o000020; 66 | pub const ONLRET: tcflag_t = 0o000040; 67 | pub const OFILL: tcflag_t = 0o000100; 68 | pub const OFDEL: tcflag_t = 0o000200; 69 | pub const NLDLY: tcflag_t = 0o000400; 70 | pub const NL0: tcflag_t = 0o000000; 71 | pub const NL1: tcflag_t = 0o000400; 72 | pub const CRDLY: tcflag_t = 0o003000; 73 | pub const CR0: tcflag_t = 0o000000; 74 | pub const CR1: tcflag_t = 0o001000; 75 | pub const CR2: tcflag_t = 0o002000; 76 | pub const CR3: tcflag_t = 0o003000; 77 | pub const TABDLY: tcflag_t = 0o014000; 78 | pub const TAB0: tcflag_t = 0o000000; 79 | pub const TAB1: tcflag_t = 0o004000; 80 | pub const TAB2: tcflag_t = 0o010000; 81 | pub const TAB3: tcflag_t = 0o014000; 82 | pub const XTABS: tcflag_t = 0o014000; 83 | pub const BSDLY: tcflag_t = 0o020000; 84 | pub const BS0: tcflag_t = 0o000000; 85 | pub const BS1: tcflag_t = 0o020000; 86 | pub const VTDLY: tcflag_t = 0o040000; 87 | pub const VT0: tcflag_t = 0o000000; 88 | pub const VT1: tcflag_t = 0o040000; 89 | pub const FFDLY: tcflag_t = 0o100000; 90 | pub const FF0: tcflag_t = 0o000000; 91 | pub const FF1: tcflag_t = 0o100000; 92 | pub const PAGEOUT: tcflag_t = 0o200000; 93 | pub const WRAP: tcflag_t = 0o400000; 94 | 95 | // c_cflag bits 96 | pub const CBAUD: tcflag_t = 0o000017; 97 | pub const CSIZE: tcflag_t = 0o000060; 98 | pub const CS5: tcflag_t = 0o000000; 99 | pub const CS6: tcflag_t = 0o000020; 100 | pub const CS7: tcflag_t = 0o000040; 101 | pub const CS8: tcflag_t = 0o000060; 102 | pub const CSTOPB: tcflag_t = 0o000100; 103 | pub const CREAD: tcflag_t = 0o000200; 104 | pub const PARENB: tcflag_t = 0o000400; 105 | pub const PARODD: tcflag_t = 0o001000; 106 | pub const HUPCL: tcflag_t = 0o002000; 107 | pub const CLOCAL: tcflag_t = 0o004000; 108 | pub const RCV1EN: tcflag_t = 0o010000; 109 | pub const XMT1EN: tcflag_t = 0o020000; 110 | pub const LOBLK: tcflag_t = 0o040000; 111 | pub const XCLUDE: tcflag_t = 0o100000; 112 | pub const CRTSXOFF: tcflag_t = 0o10000000000; 113 | pub const CRTSCTS: tcflag_t = 0o20000000000; 114 | pub const CIBAUD: tcflag_t = 0o3600000; 115 | pub const PAREXT: tcflag_t = 0o4000000; 116 | pub const CBAUDEXT: tcflag_t = 0o10000000; 117 | pub const CIBAUDEXT: tcflag_t = 0o20000000; 118 | 119 | // c_lflag bits 120 | pub const ISIG: tcflag_t = 0o000001; 121 | pub const ICANON: tcflag_t = 0o000002; 122 | pub const XCASE: tcflag_t = 0o000004; 123 | pub const ECHO: tcflag_t = 0o000010; 124 | pub const ECHOE: tcflag_t = 0o000020; 125 | pub const ECHOK: tcflag_t = 0o000040; 126 | pub const ECHONL: tcflag_t = 0o000100; 127 | pub const NOFLSH: tcflag_t = 0o000200; 128 | pub const TOSTOP: tcflag_t = 0o000400; 129 | pub const ECHOCTL: tcflag_t = 0o001000; 130 | pub const ECHOPRT: tcflag_t = 0o002000; 131 | pub const ECHOKE: tcflag_t = 0o004000; 132 | pub const DEFECHO: tcflag_t = 0o010000; 133 | pub const FLUSHO: tcflag_t = 0o020000; 134 | pub const PENDIN: tcflag_t = 0o040000; 135 | pub const IEXTEN: tcflag_t = 0o100000; 136 | 137 | // baud rates 138 | pub const B0: speed_t = 0; 139 | pub const B50: speed_t = 1; 140 | pub const B75: speed_t = 2; 141 | pub const B110: speed_t = 3; 142 | pub const B134: speed_t = 4; 143 | pub const B150: speed_t = 5; 144 | pub const B200: speed_t = 6; 145 | pub const B300: speed_t = 7; 146 | pub const B600: speed_t = 8; 147 | pub const B1200: speed_t = 9; 148 | pub const B1800: speed_t = 10; 149 | pub const B2400: speed_t = 11; 150 | pub const B4800: speed_t = 12; 151 | pub const B9600: speed_t = 13; 152 | pub const B19200: speed_t = 14; 153 | pub const B38400: speed_t = 15; 154 | pub const EXTA: speed_t = B19200; 155 | pub const EXTB: speed_t = B38400; 156 | pub const B57600: speed_t = 16; 157 | pub const B76800: speed_t = 17; 158 | pub const B115200: speed_t = 18; 159 | pub const B153600: speed_t = 19; 160 | pub const B230400: speed_t = 20; 161 | pub const B307200: speed_t = 21; 162 | pub const B460800: speed_t = 22; 163 | pub const B921600: speed_t = 23; 164 | 165 | // tcflow() 166 | pub const TCOOFF: c_int = 0; 167 | pub const TCOON: c_int = 1; 168 | pub const TCIOFF: c_int = 2; 169 | pub const TCION: c_int = 3; 170 | 171 | // tcflush() 172 | pub const TCIFLUSH: c_int = 0; 173 | pub const TCOFLUSH: c_int = 1; 174 | pub const TCIOFLUSH: c_int = 2; 175 | 176 | // tcsetattr() 177 | pub const TCSANOW: c_int = 0x540E; 178 | pub const TCSADRAIN: c_int = 0x540F; 179 | pub const TCSAFLUSH: c_int = 0x5410; 180 | -------------------------------------------------------------------------------- /src/os/solaris.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | 3 | use libc::{c_int,c_uint,c_uchar}; 4 | 5 | pub type cc_t = c_uchar; 6 | pub type speed_t = c_uint; 7 | pub type tcflag_t = c_uint; 8 | 9 | #[derive(Debug,Copy,Clone,Eq,PartialEq)] 10 | #[repr(C)] 11 | pub struct termios { 12 | pub c_iflag: tcflag_t, 13 | pub c_oflag: tcflag_t, 14 | pub c_cflag: tcflag_t, 15 | pub c_lflag: tcflag_t, 16 | pub c_cc: [cc_t; NCCS] 17 | } 18 | 19 | pub const NCCS: usize = 19; 20 | 21 | // c_cc characters 22 | pub const VINTR: usize = 0; 23 | pub const VQUIT: usize = 1; 24 | pub const VERASE: usize = 2; 25 | pub const VKILL: usize = 3; 26 | pub const VEOF: usize = 4; 27 | pub const VEOL: usize = 5; 28 | pub const VEOL2: usize = 6; 29 | pub const VMIN: usize = 4; 30 | pub const VTIME: usize = 5; 31 | pub const VSWTCH: usize = 7; 32 | pub const VSTART: usize = 8; 33 | pub const VSTOP: usize = 9; 34 | pub const VSUSP: usize = 10; 35 | pub const VDSUSP: usize = 11; 36 | pub const VREPRINT: usize = 12; 37 | pub const VDISCARD: usize = 13; 38 | pub const VWERASE: usize = 14; 39 | pub const VLNEXT: usize = 15; 40 | pub const VSTATUS: usize = 16; 41 | pub const VERASE2: usize = 17; 42 | 43 | // c_iflag bits 44 | pub const IGNBRK: tcflag_t = 0o000001; 45 | pub const BRKINT: tcflag_t = 0o000002; 46 | pub const IGNPAR: tcflag_t = 0o000004; 47 | pub const PARMRK: tcflag_t = 0o000010; 48 | pub const INPCK: tcflag_t = 0o000020; 49 | pub const ISTRIP: tcflag_t = 0o000040; 50 | pub const INLCR: tcflag_t = 0o000100; 51 | pub const IGNCR: tcflag_t = 0o000200; 52 | pub const ICRNL: tcflag_t = 0o000400; 53 | pub const IUCLC: tcflag_t = 0o001000; 54 | pub const IXON: tcflag_t = 0o002000; 55 | pub const IXANY: tcflag_t = 0o004000; 56 | pub const IXOFF: tcflag_t = 0o010000; 57 | pub const IMAXBEL: tcflag_t = 0o020000; 58 | pub const DOSMODE: tcflag_t = 0o100000; 59 | 60 | // c_oflag bits 61 | pub const OPOST: tcflag_t = 0o000001; 62 | pub const OLCUC: tcflag_t = 0o000002; 63 | pub const ONLCR: tcflag_t = 0o000004; 64 | pub const OCRNL: tcflag_t = 0o000010; 65 | pub const ONOCR: tcflag_t = 0o000020; 66 | pub const ONLRET: tcflag_t = 0o000040; 67 | pub const OFILL: tcflag_t = 0o000100; 68 | pub const OFDEL: tcflag_t = 0o000200; 69 | pub const NLDLY: tcflag_t = 0o000400; 70 | pub const NL0: tcflag_t = 0o000000; 71 | pub const NL1: tcflag_t = 0o000400; 72 | pub const CRDLY: tcflag_t = 0o003000; 73 | pub const CR0: tcflag_t = 0o000000; 74 | pub const CR1: tcflag_t = 0o001000; 75 | pub const CR2: tcflag_t = 0o002000; 76 | pub const CR3: tcflag_t = 0o003000; 77 | pub const TABDLY: tcflag_t = 0o014000; 78 | pub const TAB0: tcflag_t = 0o000000; 79 | pub const TAB1: tcflag_t = 0o004000; 80 | pub const TAB2: tcflag_t = 0o010000; 81 | pub const TAB3: tcflag_t = 0o014000; 82 | pub const XTABS: tcflag_t = 0o014000; 83 | pub const BSDLY: tcflag_t = 0o020000; 84 | pub const BS0: tcflag_t = 0o000000; 85 | pub const BS1: tcflag_t = 0o020000; 86 | pub const VTDLY: tcflag_t = 0o040000; 87 | pub const VT0: tcflag_t = 0o000000; 88 | pub const VT1: tcflag_t = 0o040000; 89 | pub const FFDLY: tcflag_t = 0o100000; 90 | pub const FF0: tcflag_t = 0o000000; 91 | pub const FF1: tcflag_t = 0o100000; 92 | pub const PAGEOUT: tcflag_t = 0o200000; 93 | pub const WRAP: tcflag_t = 0o400000; 94 | 95 | // c_cflag bits 96 | pub const CBAUD: tcflag_t = 0o000017; 97 | pub const CSIZE: tcflag_t = 0o000060; 98 | pub const CS5: tcflag_t = 0o000000; 99 | pub const CS6: tcflag_t = 0o000020; 100 | pub const CS7: tcflag_t = 0o000040; 101 | pub const CS8: tcflag_t = 0o000060; 102 | pub const CSTOPB: tcflag_t = 0o000100; 103 | pub const CREAD: tcflag_t = 0o000200; 104 | pub const PARENB: tcflag_t = 0o000400; 105 | pub const PARODD: tcflag_t = 0o001000; 106 | pub const HUPCL: tcflag_t = 0o002000; 107 | pub const CLOCAL: tcflag_t = 0o004000; 108 | pub const RCV1EN: tcflag_t = 0o010000; 109 | pub const XMT1EN: tcflag_t = 0o020000; 110 | pub const LOBLK: tcflag_t = 0o040000; 111 | pub const XCLUDE: tcflag_t = 0o100000; 112 | pub const CRTSXOFF: tcflag_t = 0o10000000000; 113 | pub const CRTSCTS: tcflag_t = 0o20000000000; 114 | pub const CIBAUD: tcflag_t = 0o3600000; 115 | pub const PAREXT: tcflag_t = 0o4000000; 116 | pub const CBAUDEXT: tcflag_t = 0o10000000; 117 | pub const CIBAUDEXT: tcflag_t = 0o20000000; 118 | 119 | // c_lflag bits 120 | pub const ISIG: tcflag_t = 0o000001; 121 | pub const ICANON: tcflag_t = 0o000002; 122 | pub const XCASE: tcflag_t = 0o000004; 123 | pub const ECHO: tcflag_t = 0o000010; 124 | pub const ECHOE: tcflag_t = 0o000020; 125 | pub const ECHOK: tcflag_t = 0o000040; 126 | pub const ECHONL: tcflag_t = 0o000100; 127 | pub const NOFLSH: tcflag_t = 0o000200; 128 | pub const TOSTOP: tcflag_t = 0o000400; 129 | pub const ECHOCTL: tcflag_t = 0o001000; 130 | pub const ECHOPRT: tcflag_t = 0o002000; 131 | pub const ECHOKE: tcflag_t = 0o004000; 132 | pub const DEFECHO: tcflag_t = 0o010000; 133 | pub const FLUSHO: tcflag_t = 0o020000; 134 | pub const PENDIN: tcflag_t = 0o040000; 135 | pub const IEXTEN: tcflag_t = 0o100000; 136 | 137 | // baud rates 138 | pub const B0: speed_t = 0; 139 | pub const B50: speed_t = 1; 140 | pub const B75: speed_t = 2; 141 | pub const B110: speed_t = 3; 142 | pub const B134: speed_t = 4; 143 | pub const B150: speed_t = 5; 144 | pub const B200: speed_t = 6; 145 | pub const B300: speed_t = 7; 146 | pub const B600: speed_t = 8; 147 | pub const B1200: speed_t = 9; 148 | pub const B1800: speed_t = 10; 149 | pub const B2400: speed_t = 11; 150 | pub const B4800: speed_t = 12; 151 | pub const B9600: speed_t = 13; 152 | pub const B19200: speed_t = 14; 153 | pub const B38400: speed_t = 15; 154 | pub const EXTA: speed_t = B19200; 155 | pub const EXTB: speed_t = B38400; 156 | pub const B57600: speed_t = 16; 157 | pub const B76800: speed_t = 17; 158 | pub const B115200: speed_t = 18; 159 | pub const B153600: speed_t = 19; 160 | pub const B230400: speed_t = 20; 161 | pub const B307200: speed_t = 21; 162 | pub const B460800: speed_t = 22; 163 | pub const B921600: speed_t = 23; 164 | 165 | // tcflow() 166 | pub const TCOOFF: c_int = 0; 167 | pub const TCOON: c_int = 1; 168 | pub const TCIOFF: c_int = 2; 169 | pub const TCION: c_int = 3; 170 | 171 | // tcflush() 172 | pub const TCIFLUSH: c_int = 0; 173 | pub const TCOFLUSH: c_int = 1; 174 | pub const TCIOFLUSH: c_int = 2; 175 | 176 | // tcsetattr() 177 | pub const TCSANOW: c_int = 0x540E; 178 | pub const TCSADRAIN: c_int = 0x540F; 179 | pub const TCSAFLUSH: c_int = 0x5410; 180 | -------------------------------------------------------------------------------- /src/os/linux.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | 3 | use libc::{c_int,c_uint,c_uchar}; 4 | 5 | pub type cc_t = c_uchar; 6 | pub type speed_t = c_uint; 7 | pub type tcflag_t = c_uint; 8 | 9 | #[derive(Debug,Copy,Clone,Eq,PartialEq)] 10 | #[repr(C)] 11 | pub struct termios { 12 | pub c_iflag: tcflag_t, 13 | pub c_oflag: tcflag_t, 14 | pub c_cflag: tcflag_t, 15 | pub c_lflag: tcflag_t, 16 | c_line: cc_t, 17 | pub c_cc: [cc_t; NCCS], 18 | c_ispeed: speed_t, 19 | c_ospeed: speed_t 20 | } 21 | 22 | pub const NCCS: usize = 32; 23 | 24 | // c_cc characters 25 | pub const VINTR: usize = 0; 26 | pub const VQUIT: usize = 1; 27 | pub const VERASE: usize = 2; 28 | pub const VKILL: usize = 3; 29 | pub const VEOF: usize = 4; 30 | pub const VTIME: usize = 5; 31 | pub const VMIN: usize = 6; 32 | pub const VSWTC: usize = 7; 33 | pub const VSTART: usize = 8; 34 | pub const VSTOP: usize = 9; 35 | pub const VSUSP: usize = 10; 36 | pub const VEOL: usize = 11; 37 | pub const VREPRINT: usize = 12; 38 | pub const VDISCARD: usize = 13; 39 | pub const VWERASE: usize = 14; 40 | pub const VLNEXT: usize = 15; 41 | pub const VEOL2: usize = 16; 42 | 43 | // c_iflag bits 44 | pub const IGNBRK: tcflag_t = 0o000001; 45 | pub const BRKINT: tcflag_t = 0o000002; 46 | pub const IGNPAR: tcflag_t = 0o000004; 47 | pub const PARMRK: tcflag_t = 0o000010; 48 | pub const INPCK: tcflag_t = 0o000020; 49 | pub const ISTRIP: tcflag_t = 0o000040; 50 | pub const INLCR: tcflag_t = 0o000100; 51 | pub const IGNCR: tcflag_t = 0o000200; 52 | pub const ICRNL: tcflag_t = 0o000400; 53 | pub const IUCLC: tcflag_t = 0o001000; 54 | pub const IXON: tcflag_t = 0o002000; 55 | pub const IXANY: tcflag_t = 0o004000; 56 | pub const IXOFF: tcflag_t = 0o010000; 57 | pub const IMAXBEL: tcflag_t = 0o020000; 58 | pub const IUTF8: tcflag_t = 0o040000; 59 | 60 | // c_oflag bits 61 | pub const OPOST: tcflag_t = 0o000001; 62 | pub const OLCUC: tcflag_t = 0o000002; 63 | pub const ONLCR: tcflag_t = 0o000004; 64 | pub const OCRNL: tcflag_t = 0o000010; 65 | pub const ONOCR: tcflag_t = 0o000020; 66 | pub const ONLRET: tcflag_t = 0o000040; 67 | pub const OFILL: tcflag_t = 0o000100; 68 | pub const OFDEL: tcflag_t = 0o000200; 69 | pub const NLDLY: tcflag_t = 0o000400; 70 | pub const NL0: tcflag_t = 0o000000; 71 | pub const NL1: tcflag_t = 0o000400; 72 | pub const CRDLY: tcflag_t = 0o003000; 73 | pub const CR0: tcflag_t = 0o000000; 74 | pub const CR1: tcflag_t = 0o001000; 75 | pub const CR2: tcflag_t = 0o002000; 76 | pub const CR3: tcflag_t = 0o003000; 77 | pub const TABDLY: tcflag_t = 0o014000; 78 | pub const TAB0: tcflag_t = 0o000000; 79 | pub const TAB1: tcflag_t = 0o004000; 80 | pub const TAB2: tcflag_t = 0o010000; 81 | pub const TAB3: tcflag_t = 0o014000; 82 | pub const BSDLY: tcflag_t = 0o020000; 83 | pub const BS0: tcflag_t = 0o000000; 84 | pub const BS1: tcflag_t = 0o020000; 85 | pub const FFDLY: tcflag_t = 0o100000; 86 | pub const FF0: tcflag_t = 0o000000; 87 | pub const FF1: tcflag_t = 0o100000; 88 | pub const VTDLY: tcflag_t = 0o040000; 89 | pub const VT0: tcflag_t = 0o000000; 90 | pub const VT1: tcflag_t = 0o040000; 91 | pub const XTABS: tcflag_t = 0o014000; 92 | 93 | // c_cflag bits 94 | pub const CBAUD: tcflag_t = 0o010017; 95 | pub const CSIZE: tcflag_t = 0o000060; 96 | pub const CS5: tcflag_t = 0o000000; 97 | pub const CS6: tcflag_t = 0o000020; 98 | pub const CS7: tcflag_t = 0o000040; 99 | pub const CS8: tcflag_t = 0o000060; 100 | pub const CSTOPB: tcflag_t = 0o000100; 101 | pub const CREAD: tcflag_t = 0o000200; 102 | pub const PARENB: tcflag_t = 0o000400; 103 | pub const PARODD: tcflag_t = 0o001000; 104 | pub const HUPCL: tcflag_t = 0o002000; 105 | pub const CLOCAL: tcflag_t = 0o004000; 106 | pub const CBAUDEX: tcflag_t = 0o010000; 107 | pub const CIBAUD: tcflag_t = 0o02003600000; 108 | pub const CMSPAR: tcflag_t = 0o10000000000; 109 | pub const CRTSCTS: tcflag_t = 0o20000000000; 110 | 111 | // c_lflag bits 112 | pub const ISIG: tcflag_t = 0o000001; 113 | pub const ICANON: tcflag_t = 0o000002; 114 | pub const XCASE: tcflag_t = 0o000004; 115 | pub const ECHO: tcflag_t = 0o000010; 116 | pub const ECHOE: tcflag_t = 0o000020; 117 | pub const ECHOK: tcflag_t = 0o000040; 118 | pub const ECHONL: tcflag_t = 0o000100; 119 | pub const NOFLSH: tcflag_t = 0o000200; 120 | pub const TOSTOP: tcflag_t = 0o000400; 121 | pub const ECHOCTL: tcflag_t = 0o001000; 122 | pub const ECHOPRT: tcflag_t = 0o002000; 123 | pub const ECHOKE: tcflag_t = 0o004000; 124 | pub const FLUSHO: tcflag_t = 0o010000; 125 | pub const PENDIN: tcflag_t = 0o040000; 126 | pub const IEXTEN: tcflag_t = 0o100000; 127 | pub const EXTPROC: tcflag_t = 0o200000; 128 | 129 | // baud rates 130 | pub const B0: speed_t = 0o000000; 131 | pub const B50: speed_t = 0o000001; 132 | pub const B75: speed_t = 0o000002; 133 | pub const B110: speed_t = 0o000003; 134 | pub const B134: speed_t = 0o000004; 135 | pub const B150: speed_t = 0o000005; 136 | pub const B200: speed_t = 0o000006; 137 | pub const B300: speed_t = 0o000007; 138 | pub const B600: speed_t = 0o000010; 139 | pub const B1200: speed_t = 0o000011; 140 | pub const B1800: speed_t = 0o000012; 141 | pub const B2400: speed_t = 0o000013; 142 | pub const B4800: speed_t = 0o000014; 143 | pub const B9600: speed_t = 0o000015; 144 | pub const B19200: speed_t = 0o000016; 145 | pub const B38400: speed_t = 0o000017; 146 | pub const EXTA: speed_t = B19200; 147 | pub const EXTB: speed_t = B38400; 148 | pub const B57600: speed_t = 0o010001; 149 | pub const B115200: speed_t = 0o010002; 150 | pub const B230400: speed_t = 0o010003; 151 | pub const B460800: speed_t = 0o010004; 152 | pub const B500000: speed_t = 0o010005; 153 | pub const B576000: speed_t = 0o010006; 154 | pub const B921600: speed_t = 0o010007; 155 | pub const B1000000: speed_t = 0o010010; 156 | pub const B1152000: speed_t = 0o010011; 157 | pub const B1500000: speed_t = 0o010012; 158 | pub const B2000000: speed_t = 0o010013; 159 | pub const B2500000: speed_t = 0o010014; 160 | pub const B3000000: speed_t = 0o010015; 161 | pub const B3500000: speed_t = 0o010016; 162 | pub const B4000000: speed_t = 0o010017; 163 | 164 | // tcflow() 165 | pub const TCOOFF: c_int = 0; 166 | pub const TCOON: c_int = 1; 167 | pub const TCIOFF: c_int = 2; 168 | pub const TCION: c_int = 3; 169 | 170 | // tcflush() 171 | pub const TCIFLUSH: c_int = 0; 172 | pub const TCOFLUSH: c_int = 1; 173 | pub const TCIOFLUSH: c_int = 2; 174 | 175 | // tcsetattr() 176 | pub const TCSANOW: c_int = 0; 177 | pub const TCSADRAIN: c_int = 1; 178 | pub const TCSAFLUSH: c_int = 2; 179 | -------------------------------------------------------------------------------- /src/os/macos.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | 3 | use libc::{c_int,c_uchar,c_ulong}; 4 | 5 | pub type tcflag_t = c_ulong; 6 | pub type cc_t = c_uchar; 7 | pub type speed_t = c_ulong; 8 | 9 | #[derive(Debug,Copy,Clone,Eq,PartialEq)] 10 | #[repr(C)] 11 | pub struct termios { 12 | pub c_iflag: tcflag_t, 13 | pub c_oflag: tcflag_t, 14 | pub c_cflag: tcflag_t, 15 | pub c_lflag: tcflag_t, 16 | pub c_cc: [cc_t; NCCS], 17 | c_ispeed: speed_t, 18 | c_ospeed: speed_t 19 | } 20 | 21 | pub const NCCS: usize = 20; 22 | 23 | // c_cc characters 24 | pub const VEOF: usize = 0; 25 | pub const VEOL: usize = 1; 26 | pub const VEOL2: usize = 2; 27 | pub const VERASE: usize = 3; 28 | pub const VWERASE: usize = 4; 29 | pub const VKILL: usize = 5; 30 | pub const VREPRINT: usize = 6; 31 | pub const VINTR: usize = 8; 32 | pub const VQUIT: usize = 9; 33 | pub const VSUSP: usize = 10; 34 | pub const VDSUSP: usize = 11; 35 | pub const VSTART: usize = 12; 36 | pub const VSTOP: usize = 13; 37 | pub const VLNEXT: usize = 14; 38 | pub const VDISCARD: usize = 15; 39 | pub const VMIN: usize = 16; 40 | pub const VTIME: usize = 17; 41 | pub const VSTATUS: usize = 18; 42 | 43 | // c_iflag bits 44 | pub const IGNBRK: tcflag_t = 0x00000001; 45 | pub const BRKINT: tcflag_t = 0x00000002; 46 | pub const IGNPAR: tcflag_t = 0x00000004; 47 | pub const PARMRK: tcflag_t = 0x00000008; 48 | pub const INPCK: tcflag_t = 0x00000010; 49 | pub const ISTRIP: tcflag_t = 0x00000020; 50 | pub const INLCR: tcflag_t = 0x00000040; 51 | pub const IGNCR: tcflag_t = 0x00000080; 52 | pub const ICRNL: tcflag_t = 0x00000100; 53 | pub const IXON: tcflag_t = 0x00000200; 54 | pub const IXOFF: tcflag_t = 0x00000400; 55 | pub const IXANY: tcflag_t = 0x00000800; 56 | pub const IMAXBEL: tcflag_t = 0x00002000; 57 | pub const IUTF8: tcflag_t = 0x00004000; 58 | 59 | // c_oflag bits 60 | pub const OPOST: tcflag_t = 0x00000001; 61 | pub const ONLCR: tcflag_t = 0x00000002; 62 | pub const OXTABS: tcflag_t = 0x00000004; 63 | pub const ONOEOT: tcflag_t = 0x00000008; 64 | pub const OCRNL: tcflag_t = 0x00000010; 65 | pub const ONOCR: tcflag_t = 0x00000020; 66 | pub const ONLRET: tcflag_t = 0x00000040; 67 | pub const OFILL: tcflag_t = 0x00000080; 68 | pub const NLDLY: tcflag_t = 0x00000300; 69 | pub const TABDLY: tcflag_t = 0x00000c04; 70 | pub const CRDLY: tcflag_t = 0x00003000; 71 | pub const FFDLY: tcflag_t = 0x00004000; 72 | pub const BSDLY: tcflag_t = 0x00008000; 73 | pub const VTDLY: tcflag_t = 0x00010000; 74 | pub const OFDEL: tcflag_t = 0x00020000; 75 | pub const NL0: tcflag_t = 0x00000000; 76 | pub const NL1: tcflag_t = 0x00000100; 77 | pub const NL2: tcflag_t = 0x00000200; 78 | pub const NL3: tcflag_t = 0x00000300; 79 | pub const TAB0: tcflag_t = 0x00000000; 80 | pub const TAB1: tcflag_t = 0x00000400; 81 | pub const TAB2: tcflag_t = 0x00000800; 82 | pub const TAB3: tcflag_t = 0x00000004; 83 | pub const CR0: tcflag_t = 0x00000000; 84 | pub const CR1: tcflag_t = 0x00001000; 85 | pub const CR2: tcflag_t = 0x00002000; 86 | pub const CR3: tcflag_t = 0x00003000; 87 | pub const FF0: tcflag_t = 0x00000000; 88 | pub const FF1: tcflag_t = 0x00004000; 89 | pub const BS0: tcflag_t = 0x00000000; 90 | pub const BS1: tcflag_t = 0x00008000; 91 | pub const VT0: tcflag_t = 0x00000000; 92 | pub const VT1: tcflag_t = 0x00010000; 93 | 94 | // c_cflag bits 95 | pub const CIGNORE: tcflag_t = 0x00000001; 96 | pub const CSIZE: tcflag_t = 0x00000300; 97 | pub const CS5: tcflag_t = 0x00000000; 98 | pub const CS6: tcflag_t = 0x00000100; 99 | pub const CS7: tcflag_t = 0x00000200; 100 | pub const CS8: tcflag_t = 0x00000300; 101 | pub const CSTOPB: tcflag_t = 0x00000400; 102 | pub const CREAD: tcflag_t = 0x00000800; 103 | pub const PARENB: tcflag_t = 0x00001000; 104 | pub const PARODD: tcflag_t = 0x00002000; 105 | pub const HUPCL: tcflag_t = 0x00004000; 106 | pub const CLOCAL: tcflag_t = 0x00008000; 107 | pub const CCTS_OFLOW: tcflag_t = 0x00010000; 108 | pub const CRTSCTS: tcflag_t = CCTS_OFLOW | CRTS_IFLOW; 109 | pub const CRTS_IFLOW: tcflag_t = 0x00020000; 110 | pub const CDTR_IFLOW: tcflag_t = 0x00040000; 111 | pub const CDSR_OFLOW: tcflag_t = 0x00080000; 112 | pub const CCAR_OFLOW: tcflag_t = 0x00100000; 113 | pub const MDMBUF: tcflag_t = 0x00100000; 114 | 115 | // c_lflag bits 116 | pub const ECHOKE: tcflag_t = 0x00000001; 117 | pub const ECHOE: tcflag_t = 0x00000002; 118 | pub const ECHOK: tcflag_t = 0x00000004; 119 | pub const ECHO: tcflag_t = 0x00000008; 120 | pub const ECHONL: tcflag_t = 0x00000010; 121 | pub const ECHOPRT: tcflag_t = 0x00000020; 122 | pub const ECHOCTL: tcflag_t = 0x00000040; 123 | pub const ISIG: tcflag_t = 0x00000080; 124 | pub const ICANON: tcflag_t = 0x00000100; 125 | pub const ALTWERASE: tcflag_t = 0x00000200; 126 | pub const IEXTEN: tcflag_t = 0x00000400; 127 | pub const EXTPROC: tcflag_t = 0x00000800; 128 | pub const TOSTOP: tcflag_t = 0x00400000; 129 | pub const FLUSHO: tcflag_t = 0x00800000; 130 | pub const NOKERNINFO: tcflag_t = 0x02000000; 131 | pub const PENDIN: tcflag_t = 0x20000000; 132 | pub const NOFLSH: tcflag_t = 0x80000000; 133 | 134 | // baud speeds 135 | pub const B0: speed_t = 0; 136 | pub const B50: speed_t = 50; 137 | pub const B75: speed_t = 75; 138 | pub const B110: speed_t = 110; 139 | pub const B134: speed_t = 134; 140 | pub const B150: speed_t = 150; 141 | pub const B200: speed_t = 200; 142 | pub const B300: speed_t = 300; 143 | pub const B600: speed_t = 600; 144 | pub const B1200: speed_t = 1200; 145 | pub const B1800: speed_t = 1800; 146 | pub const B2400: speed_t = 2400; 147 | pub const B4800: speed_t = 4800; 148 | pub const B9600: speed_t = 9600; 149 | pub const B19200: speed_t = 19200; 150 | pub const B38400: speed_t = 38400; 151 | pub const B7200: speed_t = 7200; 152 | pub const B14400: speed_t = 14400; 153 | pub const B28800: speed_t = 28800; 154 | pub const B57600: speed_t = 57600; 155 | pub const B76800: speed_t = 76800; 156 | pub const B115200: speed_t = 115200; 157 | pub const B230400: speed_t = 230400; 158 | pub const EXTA: speed_t = 19200; 159 | pub const EXTB: speed_t = 38400; 160 | 161 | // tcflow() 162 | pub const TCOOFF: c_int = 1; 163 | pub const TCOON: c_int = 2; 164 | pub const TCIOFF: c_int = 3; 165 | pub const TCION: c_int = 4; 166 | 167 | // tcflush() 168 | pub const TCIFLUSH: c_int = 1; 169 | pub const TCOFLUSH: c_int = 2; 170 | pub const TCIOFLUSH: c_int = 3; 171 | 172 | // tcsetattr() 173 | pub const TCSANOW: c_int = 0; 174 | pub const TCSADRAIN: c_int = 1; 175 | pub const TCSAFLUSH: c_int = 2; 176 | pub const TCSASOFT: c_int = 0x10; 177 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Termios is a pervasive API on Unix-like systems. One person can't possibly be an expert is all of 4 | the platforms that `termios-rs` may want to target. This document provides guidelines for how we can 5 | work together as complete strangers while maintaining a high standard for quality. 6 | 7 | ## General Guidelines 8 | 9 | * Above all, don't be a jerk. You won't get what you want that way. 10 | 11 | * Please try to keep discussion focused on improving this project. Don't use the issue tracker to 12 | promote other projects. A brief mention of another project as it relates to the development of 13 | this project is okay. This also isn't the place for political activism. 14 | 15 | * Remember that nobody is paid to work on this project. There are no contractual obligations, and no 16 | promises have been made. Maintainers have friends, family, kids, hobbies, and responsibilities 17 | outside of this project. Please calibrate your expectations accordingly. 18 | 19 | * Maintainers have the final say. The maintainers are not your co-workers and they don't work for 20 | you. Please calibrate your expectations accordingly. 21 | 22 | * Avoid "+1" or similar comments. Try to find a more constructive way to move the project forward. A 23 | comment with how you've tested a patch and your results adds more value than "+1" while serving 24 | the same purpose. See "[Reviewing Patches](#reviewing-patches)" below for ideas of how you can 25 | help. 26 | 27 | * If you want to see something get done, the best way is to roll up your sleeves and do it. Read 28 | below for details on how you can help. 29 | 30 | ## Moderating 31 | 32 | Some people just don't know how to behave on the internet. Unfortunately, this is one of the leading 33 | causes for maintainers to walk away from their projects. That makes moderating user behavior one of 34 | most important things that any mentally-stable adult can do to contribute to an open source project. 35 | Being a moderator doesn't require being blessed with a special status. Anyone can help. 36 | 37 | If you see anyone being rude, acting with a sense of entitlement, putting down others or their work, 38 | arguing in bad faith, or in any other way making the project an unpleasant place to spend one's 39 | time, please call out the bad behavior. As a maintainer, it helps to see that we're not on our own 40 | when dealing with bad behavior. 41 | 42 | This includes enforcing theses contributing guidelines. If you see patches or issues that don't 43 | appear to be based on these guidelines, please ask the submitter to provide the missing details. 44 | 45 | If you'd prefer to email me privately about someone's behavior, please do so. My email can be found 46 | in public profiles or the project's commit history. 47 | 48 | ## Adding Support for New Platforms 49 | 50 | The currently supported platforms are listed in the README. If an operating system and architecture 51 | aren't listed there, it means that nobody has confirmed that `termios-rs` works on that platform. 52 | The following sections describe different ways that one can help add support for a new platform. 53 | The guidelines in this section are meant to increase the chances that a patch can land smoothly the 54 | first time that a maintainer reviews it. 55 | 56 | ### Sending Patches 57 | 58 | Patches should be based on reading the C header file `termios.h`. This is often located at 59 | `/usr/include/termios.h` or `/usr/include/sys/termios.h`. You may have to install a package to get 60 | the header files. 61 | 62 | IMPORTANT: Please do not count on a platform being so similar to another platform that you can just 63 | copy the definitions. I'm pretty sure every patch that has been submitted that way has proven the 64 | assumption to be wrong. That just wastes everyone's time. Don't submit patches without testing them. 65 | 66 | To make a patch for a new platform, you'll need to setup the target platform with a working Rust 67 | compiler and `termios.h` header file. Sometimes a working C compiler can help, too. Please take note 68 | of the steps you use to setup your platform so that you can provide testing guidance when submitting 69 | your patch. See "[Testing Guidance](#testing-guidance)," for details. 70 | 71 | 1. Start by creating a new file in `src/os/` for the target platform. To keep things consistent, 72 | pick a name that matches the value of Rust's `target_os` configuration variable, e.g., 73 | `src/os/freebsd.rs`. 74 | 75 | 2. Adjust the `use` and `mod` items in `src/os/mod.rs`. 76 | 77 | 3. Add an example to the doctest under "OS-Specific Extensions" in `src/lib.rs`. `cargo test` won't 78 | pass without it. 79 | 80 | 3. Read through the `termios.h` header file and transliterate it to Rust. Someone reading through 81 | the Rust file and C header file side-by-side should be able to easily verify that they produce 82 | the same values. That means: 83 | 84 | * Values in the Rust file should be defined in the same radix (decimal, octal, hexidecimal) as 85 | the C header file. 86 | 87 | * Definitions should appear roughly in the same order that they appear in the C header file. 88 | Please try to keep them grouped similar to other platforms. That means keeping `c_cc` character 89 | indexes together, `c_iflag` bits together, `c_oflag` bits together, etc. But within each of 90 | those groups, match the order of the C header file. 91 | 92 | One exception to transliterating the header file is to expand macros to their literal value. 93 | For example, 94 | 95 | ```c 96 | #define _TIOC 'T' 97 | #define TCSANOW (_TIOC|14) 98 | ``` 99 | 100 | should be reduced to 101 | 102 | ```rust 103 | pub const TCSANOW: c_int = 0x005E; 104 | ``` 105 | 106 | In this case, simplicity is the overriding concern. This is where having a C compiler on the 107 | target platform can help. To avoid error in computing the literal value, you can let a C 108 | compiler do it for you: 109 | 110 | ```c 111 | #include 112 | #include 113 | #include 114 | 115 | int main(void) 116 | { 117 | printf("TCSANOW = 0x%04X\n", TCSANOW); 118 | return EXIT_SUCCESS; 119 | } 120 | ``` 121 | 122 | 4. Check which of the functions in `src/ffi.rs` the target platform implements (look for them in 123 | `termios.h`). If the target platform doesn't implement one or more of them, adjust the `#[cfg]` 124 | items in `src/ffi.rs` to use the fallback imlementations. (`cfmakeraw()` and `cfsetspeed()` are 125 | technically not part of the [POSIX standard for termios][posix]. Many operating systems provide 126 | them, but some do not.) 127 | 128 | 5. Make sure `cargo build` and `cargo test` for `termios-rs` both pass on the target platform. 129 | 130 | 6. Optionally, test some projects that depend on `termios-rs`. Some popular projects that depend on 131 | `termios-rs` include: 132 | 133 | * [`serial-rs`](https://github.com/dcuddeback/serial-rs) 134 | 135 | * [`bat`](https://github.com/sharkdp/bat) 136 | 137 | When submitting a patch, please provide testing guidance. See the section, "[Testing 138 | Guidance](#testing-guidance)," for details. 139 | 140 | ### Reviewing Patches 141 | 142 | The best way to help land an existing patch is to review it. If you review a patch, please leave a 143 | review comment on its submission so that maintainers can see how many eyes have looked at a patch. 144 | If you don't comment, we won't know. And commenting on a patch with what you've done to review and 145 | test it is much more helpful than "+1" comments. 146 | 147 | See the section, "[Testing](#testing)," for details on how to test a patch. If you tested something 148 | that others hadn't, such as a different version of an operating system or a different reverse 149 | dependency, please comment with details of what you tested and the results. 150 | 151 | Check the patch for conformance to the guidelines described in "[Sending 152 | Patches](#sending-patches)." Feel free to add line comments where you spot anything that looks 153 | incorrect. Whether or not you spot any errors, please leave a review comment so that maintainers 154 | know how much peer-review a patch has received. 155 | 156 | Make sure that the patch was submitted with sufficient testing guidance. See the section, "[Testing 157 | Guidance](#testing-guidance)," for details. If the guidance seems incomplete, ask the submitter to 158 | provide additional details or add the relevant details yourself if you can. If you have an 159 | alternative way of testing, feel free to provide those details according to the "[Testing 160 | Guidance](#testing-guidance)" section. 161 | 162 | ### Testing 163 | 164 | If you're interested in a different architecture of an existing operating system, it may be just a 165 | matter of testing the new architecture. Or if you see a patch for a platform you're interested in, 166 | you can help test that patch, too. 167 | 168 | To test platform support, you'll need to have a working Rust compiler on the target platform, and 169 | you'll need the C header files for `termios`. A working C compiler can help, too. 170 | 171 | 1. Find the Rust definitions for the platform you're testing. This will be in 172 | `src/os/{platform}.rs`, e.g., `src/os/freebsd.rs` for FreeBSD. 173 | 174 | 2. Find the C header file for your platform. This is often located at `/usr/include/termios.h` or 175 | `/usr/include/sys/termios.h`. On some platforms, you may have to install a package to get the 176 | header files. (If so, please report which package.) 177 | 178 | 3. Verify that the definitions in the Rust code match the definitions from the C header file. If 179 | reviewing a new patch submission, verify that the values are defined in the same radix as the C 180 | header file and are defined in roughly the same order. If the submitter followed the guidelines 181 | in "[Sending Patches](#sending-patches)," this step should go smoothly. 182 | 183 | 4. Verify that `cargo build` and `cargo test` for `termios-rs` both succeed on the target platform. 184 | 185 | 5. Optionally, test some projects that depend on `termios-rs`. Some popular projects that depend on 186 | `termios-rs` include: 187 | 188 | * [`serial-rs`](https://github.com/dcuddeback/serial-rs) 189 | 190 | * [`bat`](https://github.com/sharkdp/bat) 191 | 192 | Please report back on your findings. Knowing that a platform has had several sets of eyes looking at 193 | it is helpful. 194 | 195 | If you tested a new architecture for an already-supported operating system and everything appears 196 | correct, please submit a patch to add the architecture to the list of supported platforms in the 197 | README. When submitting such a patch, please describe what you tested, including any reverse 198 | dependencies, and provide any testing guidance you can for the maintainers. See the section, 199 | "[Testing Guidance](#testing-guidance)," for details. 200 | 201 | ### Testing Guidance 202 | 203 | Before landing a patch, a maintainer will need to verify the patch on the target platform. That 204 | means a maintainer will need to setup a virtual machine running the target platform, setup SSH 205 | access, and install a working Rust compiler, `termios.h` header files, and possibly a C compiler. 206 | Any instructions you can provide to help a maintainer or other testers through those steps will help 207 | land the patch quicker. Try to be as complete and precise as possible, including full commands where 208 | appropriate. 209 | 210 | Some helpful tips could include: 211 | 212 | * How to obtain installation media for the target platform. Some platforms are made up of many 213 | distributions. Some less popular platforms may not have official Rust support or may have 214 | recently gained Rust support in their latest nightly snapshot. If this matters, please point to 215 | the release channel that provides the greatest chance of success of getting things working. At 216 | the very least, just tell us what you used (which distribution, version, and release channel, if 217 | applicable). 218 | 219 | * Any special steps to setup a virtual machine. How should the virtual hardware be setup? For less 220 | popular architectures, providing specific commands to use with QEMU or libvirt would be ideal. 221 | If you only have instructions for other hypervisors, go ahead and provide them. 222 | 223 | * How to setup and configure SSH access. What packages need to be installed? Is there a 224 | configuration file that needs to be edited? 225 | 226 | * How to install Rust and Cargo. Does `rustup` work on the target platform? Is Rust in the 227 | platform's package manager? What's the package name? Does it need to be installed from an 228 | unofficial channel? 229 | 230 | * How to install the termios header files and a C compiler. Usually these are just packages that 231 | needs to be installed. Which packages? 232 | 233 | The easier it is for a maintainer to verify a patch, the easier it will be for a maintainer to land 234 | the patch. :) 235 | 236 | ### Requesting Support for New Platforms 237 | 238 | Platforms that have been tested are listed in the README. Any platform that implements the termios 239 | API is fair game to add to `termios-rs`, so there is implicitly an open ticket for any platform not 240 | listed in the README. If you're interested in a platform that isn't listed in the README, you may 241 | open a ticket to request support, but that won't change much. Someone will need to roll up their 242 | sleeves and do the work to support it. At most, a ticket provides a place to coordinate who's 243 | working on support for a platform. 244 | 245 | ## Other Requests 246 | 247 | There may occasionally be a small enhancement worth considering, like adding a trait implementation 248 | or adding to the documentation. Go ahead and open tickets or send patches for small enhancements. 249 | 250 | Most other requests are probably out of scope. `termios-rs` aims to be a very stable, low-churn 251 | library with wide platform support. There's little value in constantly refactoring it, adding 252 | dependencies, or debating design patterns. 253 | 254 | This also isn't the place to ask for help with general programming questions or how to use the 255 | termios API. The scope of this project is to provide the Rust bindings for the termios API. The 256 | termios API itself is standardized by POSIX and provided by your operating system. The [POSIX 257 | standard][posix], your operating system's manual pages, and internet searches are your best 258 | resources for termios-specific help. 259 | 260 | [posix]: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/termios.h.html 261 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! The `termios` crate provides Rust bindings for the POSIX termios API that is implemented on 2 | //! Unix operating systems. The termios API is defined in the [IEEE Std 1003.1 ("POSIX.1") 3 | //! specification](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/termios.h.html). 4 | //! 5 | //! ## Getting Started 6 | //! 7 | //! The termios API operates on file descriptors that are associated with terminal devices, e.g., 8 | //! `/dev/tty*`. When used with other file descriptors, termios functions return an error. All 9 | //! functions that are part of the POSIX standard are included in the `termios` crate. Where file 10 | //! descriptors are expected, the type `std::os::unix::io::RawFd` is used, and integer error codes 11 | //! are translated to `std::io::Result`. 12 | //! 13 | //! A major feature of the termios API is configuring a terminal device's parameters. The POSIX 14 | //! standard defines a `termios` structure that contains the parameters and several functions for 15 | //! manipulating the parameters. The `termios` crate defines a safe constructor that returns a 16 | //! [`Termios`](struct.Termios.html) struct populated with the parameters of an open terminal 17 | //! device: 18 | //! 19 | //! ```no_run 20 | //! use termios::*; 21 | //! # let fd = 1; 22 | //! let mut termios = Termios::from_fd(fd).unwrap(); 23 | //! ``` 24 | //! 25 | //! The [`Termios`](struct.Termios.html) struct provides access to the fields defined in the POSIX 26 | //! standard (`c_iflag`, `c_oflag`, `c_cflag`, `c_lflag`, and `c_cc`): 27 | //! 28 | //! ```no_run 29 | //! # use termios::*; 30 | //! # let fd = 1; 31 | //! # let mut termios = Termios::from_fd(fd).unwrap(); 32 | //! termios.c_cflag |= CREAD | CLOCAL; 33 | //! termios.c_lflag &= !(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG | IEXTEN); 34 | //! termios.c_oflag &= !OPOST; 35 | //! termios.c_iflag &= !(INLCR | IGNCR | ICRNL | IGNBRK); 36 | //! 37 | //! termios.c_cc[VMIN] = 0; 38 | //! termios.c_cc[VTIME] = 0; 39 | //! ``` 40 | //! 41 | //! The [`Termios`](struct.Termios.html) struct can also be manipulated using any of the standard 42 | //! termios API functions: 43 | //! 44 | //! ```no_run 45 | //! # use termios::*; 46 | //! # let fd = 1; 47 | //! # let mut termios = Termios::from_fd(fd).unwrap(); 48 | //! cfgetispeed(&termios); 49 | //! cfgetospeed(&termios); 50 | //! cfsetispeed(&mut termios, B9600).unwrap(); 51 | //! cfsetospeed(&mut termios, B9600).unwrap(); 52 | //! tcsetattr(fd, TCSANOW, &termios).unwrap(); 53 | //! ``` 54 | //! 55 | //! ## Portability 56 | //! 57 | //! The `termios` crate is organized in a way to help write portable code, while also allowing 58 | //! access to OS-specific functionality when necessary. 59 | //! 60 | //! The crate root contains types, constants, and function definitions that are common across Unix 61 | //! operating systems. Most of the definitions in the crate root are from the POSIX standard; 62 | //! however, support for the standard may differ across operating systems. A couple functions in 63 | //! the crate root are not part of the POSIX standard, but are included in the crate root because 64 | //! they are widely available across Unix operating systems. 65 | //! 66 | //! To write portable code, import the `termios` crate and use only the definitions from the crate 67 | //! root. 68 | //! 69 | //! ### OS-Specific Extensions 70 | //! 71 | //! Each operating system may define extensions to the POSIX API. To make it clear when code 72 | //! depends on OS-specific definitions, any non-standard definitions are exported in the 73 | //! `termios::os` module. Programs that depend on OS-specific functionality must explicity opt-in. 74 | //! When writing portable code that depends on OS-specific definitions, it will often be necessary 75 | //! to use `#[cfg(...)]` attributes to support alternative implementations. The following is an 76 | //! example of a portable function that sets the maximum speed on a `Termios` struct. 77 | //! 78 | //! ```no_run 79 | //! use std::io; 80 | //! use termios::{Termios,cfsetspeed}; 81 | //! 82 | //! #[cfg(target_os = "linux")] 83 | //! fn set_fastest_speed(termios: &mut Termios) -> io::Result<()> { 84 | //! cfsetspeed(termios, termios::os::linux::B4000000) 85 | //! } 86 | //! 87 | //! #[cfg(target_os = "macos")] 88 | //! fn set_fastest_speed(termios: &mut Termios) -> io::Result<()> { 89 | //! cfsetspeed(termios, termios::os::macos::B230400) 90 | //! } 91 | //! 92 | //! #[cfg(target_os = "freebsd")] 93 | //! fn set_fastest_speed(termios: &mut Termios) -> io::Result<()> { 94 | //! cfsetspeed(termios, termios::os::freebsd::B921600) 95 | //! } 96 | //! 97 | //! #[cfg(target_os = "openbsd")] 98 | //! fn set_fastest_speed(termios: &mut Termios) -> io::Result<()> { 99 | //! cfsetspeed(termios, termios::os::openbsd::B921600) 100 | //! } 101 | //! 102 | //! #[cfg(target_os = "netbsd")] 103 | //! fn set_fastest_speed(termios: &mut Termios) -> io::Result<()> { 104 | //! cfsetspeed(termios, termios::os::netbsd::B921600) 105 | //! } 106 | //! 107 | //! #[cfg(target_os = "dragonfly")] 108 | //! fn set_fastest_speed(termios: &mut Termios) -> io::Result<()> { 109 | //! cfsetspeed(termios, termios::os::dragonfly::B230400) 110 | //! } 111 | //! 112 | //! #[cfg(target_os = "solaris")] 113 | //! fn set_fastest_speed(termios: &mut Termios) -> io::Result<()> { 114 | //! cfsetspeed(termios, termios::os::solaris::B921600) 115 | //! } 116 | //! 117 | //! #[cfg(target_os = "illumos")] 118 | //! fn set_fastest_speed(termios: &mut Termios) -> io::Result<()> { 119 | //! cfsetspeed(termios, termios::os::illumos::B921600) 120 | //! } 121 | //! 122 | //! # let fd = 1; 123 | //! let mut termios = Termios::from_fd(fd).unwrap(); 124 | //! set_fastest_speed(&mut termios).unwrap(); 125 | //! ``` 126 | 127 | extern crate libc; 128 | 129 | use std::io; 130 | use std::mem; 131 | use std::ops::{Deref,DerefMut}; 132 | use std::os::unix::io::RawFd; 133 | 134 | use libc::{c_int,pid_t}; 135 | 136 | pub use ::os::target::{cc_t,speed_t,tcflag_t}; // types 137 | pub use ::os::target::{VEOF,VEOL,VERASE,VINTR,VKILL,VMIN,VQUIT,VSTART,VSTOP,VSUSP,VTIME}; // c_cc subscripts 138 | pub use ::os::target::{BRKINT,ICRNL,IGNBRK,IGNCR,IGNPAR,INLCR,INPCK,ISTRIP,IXANY,IXOFF,IXON,PARMRK}; // input modes 139 | pub use ::os::target::{OPOST,ONLCR,OCRNL,ONOCR,ONLRET}; // output modes 140 | pub use ::os::target::{B0,B50,B75,B110,B134,B150,B200,B300,B600,B1200,B1800,B2400,B4800,B9600,B19200,B38400}; // baud rate selection 141 | pub use ::os::target::{CSIZE,CS5,CS6,CS7,CS8,CSTOPB,CREAD,PARENB,PARODD,HUPCL,CLOCAL}; // control modes 142 | pub use ::os::target::{ECHO,ECHOE,ECHOK,ECHONL,ICANON,IEXTEN,ISIG,NOFLSH,TOSTOP}; // local modes 143 | pub use ::os::target::{TCSANOW,TCSADRAIN,TCSAFLUSH}; // attribute selection 144 | pub use ::os::target::{TCIFLUSH,TCIOFLUSH,TCOFLUSH,TCIOFF,TCION,TCOOFF,TCOON}; // line control 145 | 146 | pub mod ffi; 147 | pub mod os; 148 | 149 | 150 | /// Unix terminal I/O control structure. 151 | /// 152 | /// The `Termios` structure is a thin wrapper for the OS-specific `termios` struct. The only safe 153 | /// way to obtain a `Termios` structure is to fill one from a file descriptor with 154 | /// [`Termios::from_fd()`](#method.from_fd), after which it can be treated just like the POSIX 155 | /// `termios` struct. It provides access to the standard fields of the `termios` struct (`c_iflag`, 156 | /// `c_oflag`, `c_cflag`, `c_lflag`, and `c_cc`) through the `Deref` and `DerefMut` traits. 157 | /// 158 | /// ## Example 159 | /// 160 | /// The following is an example of how one might setup a file descriptor for a serial port: 161 | /// 162 | /// ```no_run 163 | /// use std::io; 164 | /// use std::os::unix::io::RawFd; 165 | /// 166 | /// fn setup_serial(fd: RawFd) -> io::Result<()> { 167 | /// use termios::*; 168 | /// 169 | /// let mut termios = try!(Termios::from_fd(fd)); 170 | /// 171 | /// termios.c_cflag |= CREAD | CLOCAL; 172 | /// termios.c_lflag &= !(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG | IEXTEN); 173 | /// termios.c_oflag &= !OPOST; 174 | /// termios.c_iflag &= !(INLCR | IGNCR | ICRNL | IGNBRK); 175 | /// 176 | /// termios.c_cc[VMIN] = 0; 177 | /// termios.c_cc[VTIME] = 0; 178 | /// 179 | /// try!(cfsetspeed(&mut termios, B9600)); 180 | /// try!(tcsetattr(fd, TCSANOW, &mut termios)); 181 | /// 182 | /// Ok(()) 183 | /// } 184 | /// ``` 185 | #[derive(Debug,Copy,Clone,Eq,PartialEq)] 186 | pub struct Termios { 187 | inner: ::os::target::termios 188 | } 189 | 190 | impl Termios { 191 | /// Creates a `Termios` structure based on the current settings of a file descriptor. 192 | /// 193 | /// `fd` must be an open file descriptor for a terminal device. 194 | pub fn from_fd(fd: RawFd) -> io::Result { 195 | let mut termios = unsafe { mem::uninitialized() }; 196 | 197 | match tcgetattr(fd, &mut termios) { 198 | Ok(_) => Ok(termios), 199 | Err(err) => Err(err) 200 | } 201 | } 202 | 203 | fn inner(&self) -> &::os::target::termios { 204 | &self.inner 205 | } 206 | 207 | fn inner_mut(&mut self) -> &mut ::os::target::termios { 208 | &mut self.inner 209 | } 210 | } 211 | 212 | impl Deref for Termios { 213 | type Target = ::os::target::termios; 214 | 215 | fn deref(&self) -> &::os::target::termios { 216 | self.inner() 217 | } 218 | } 219 | 220 | impl DerefMut for Termios { 221 | fn deref_mut(&mut self) -> &mut ::os::target::termios { 222 | self.inner_mut() 223 | } 224 | } 225 | 226 | 227 | /// Gets the input baud rate stored in a `Termios` structure. 228 | /// 229 | /// # Examples 230 | /// 231 | /// ``` 232 | /// # use std::mem; 233 | /// # use termios::{Termios,B9600,cfsetispeed,cfgetispeed}; 234 | /// # let mut termios = unsafe { mem::uninitialized() }; 235 | /// cfsetispeed(&mut termios, B9600).unwrap(); 236 | /// assert_eq!(cfgetispeed(&termios), B9600); 237 | /// ``` 238 | pub fn cfgetispeed(termios: &Termios) -> speed_t { 239 | unsafe { ffi::cfgetispeed(termios.inner()) } 240 | } 241 | 242 | /// Gets the output baud rate stored in a `Termios` structure. 243 | /// 244 | /// # Examples 245 | /// 246 | /// ``` 247 | /// # use std::mem; 248 | /// # use termios::{Termios,B9600,cfsetospeed,cfgetospeed}; 249 | /// # let mut termios = unsafe { mem::uninitialized() }; 250 | /// cfsetospeed(&mut termios, B9600).unwrap(); 251 | /// assert_eq!(cfgetospeed(&termios), B9600); 252 | /// ``` 253 | pub fn cfgetospeed(termios: &Termios) -> speed_t { 254 | unsafe { ffi::cfgetospeed(termios.inner()) } 255 | } 256 | 257 | /// Sets the input baud rate. 258 | /// 259 | /// This function only sets the necessary values on the given `Termios` structure. The settings are 260 | /// applied by a subsequent call to [`tcsetattr()`](fn.tcsetattr.html). 261 | /// 262 | /// # Parameters 263 | /// 264 | /// * `termios` should be a mutable reference to a `Termios` structure. 265 | /// * `speed` should be one of the baud rate constants: 266 | /// - `B0` 267 | /// - `B50` 268 | /// - `B75` 269 | /// - `B110` 270 | /// - `B134` 271 | /// - `B150` 272 | /// - `B200` 273 | /// - `B300` 274 | /// - `B600` 275 | /// - `B1200` 276 | /// - `B1800` 277 | /// - `B2400` 278 | /// - `B4800` 279 | /// - `B9600` 280 | /// - `B19200` 281 | /// - `B38400` 282 | /// - any OS-specific baud rate defined in [`termios::os`](os/index.html). 283 | /// 284 | /// A value of `B0` for `speed` sets the input baud rate to be the same as the output baud rate. 285 | /// 286 | /// # Examples 287 | /// 288 | /// ``` 289 | /// # use std::mem; 290 | /// # use termios::{Termios,B9600,cfsetispeed,cfgetispeed}; 291 | /// # let mut termios = unsafe { mem::uninitialized() }; 292 | /// cfsetispeed(&mut termios, B9600).unwrap(); 293 | /// assert_eq!(cfgetispeed(&termios), B9600); 294 | /// ``` 295 | pub fn cfsetispeed(termios: &mut Termios, speed: speed_t) -> io::Result<()> { 296 | io_result(unsafe { ffi::cfsetispeed(termios.inner_mut(), speed) }) 297 | } 298 | 299 | /// Sets the output baud rate. 300 | /// 301 | /// This function only sets the necessary values on the given `Termios` structure. The settings are 302 | /// applied on a successful call to [`tcsetattr()`](fn.tcsetattr.html). 303 | /// 304 | /// # Parameters 305 | /// 306 | /// * `termios` should be a mutable reference to a `Termios` structure. 307 | /// * `speed` should be one of the baud rate constants: 308 | /// - `B0` (hang up) 309 | /// - `B50` 310 | /// - `B75` 311 | /// - `B110` 312 | /// - `B134` 313 | /// - `B150` 314 | /// - `B200` 315 | /// - `B300` 316 | /// - `B600` 317 | /// - `B1200` 318 | /// - `B1800` 319 | /// - `B2400` 320 | /// - `B4800` 321 | /// - `B9600` 322 | /// - `B19200` 323 | /// - `B38400` 324 | /// - any OS-specific baud rate defined in [`termios::os`](os/index.html). 325 | /// 326 | /// A value of `B0` for `speed` deasserts the modem control lines when applied with 327 | /// [`tcsetattr()`](fn.tcsetattr.html). This normally has the effect of disconnecting the line. 328 | /// 329 | /// # Examples 330 | /// 331 | /// ``` 332 | /// # use std::mem; 333 | /// # use termios::{Termios,B9600,cfsetospeed,cfgetospeed}; 334 | /// # let mut termios = unsafe { mem::uninitialized() }; 335 | /// cfsetospeed(&mut termios, B9600).unwrap(); 336 | /// assert_eq!(cfgetospeed(&termios), B9600); 337 | /// ``` 338 | pub fn cfsetospeed(termios: &mut Termios, speed: speed_t) -> io::Result<()> { 339 | io_result(unsafe { ffi::cfsetospeed(termios.inner_mut(), speed) }) 340 | } 341 | 342 | /// Sets input and output baud rates. 343 | /// 344 | /// This function only sets the necessary values on the given `Termios` structure. The settings are 345 | /// applied on a successful call to [`tcsetattr()`](fn.tcsetattr.html). 346 | /// 347 | /// # Parameters 348 | /// 349 | /// * `termios` should be a mutable reference to a `Termios` structure. 350 | /// * `speed` should be one of the baud rate constants: 351 | /// - `B0` 352 | /// - `B50` 353 | /// - `B75` 354 | /// - `B110` 355 | /// - `B134` 356 | /// - `B150` 357 | /// - `B200` 358 | /// - `B300` 359 | /// - `B600` 360 | /// - `B1200` 361 | /// - `B1800` 362 | /// - `B2400` 363 | /// - `B4800` 364 | /// - `B9600` 365 | /// - `B19200` 366 | /// - `B38400` 367 | /// - any OS-specific baud rate defined in [`termios::os`](os/index.html). 368 | /// 369 | /// # Examples 370 | /// 371 | /// ``` 372 | /// # use std::mem; 373 | /// # use termios::{Termios,B9600,cfsetspeed,cfgetispeed,cfgetospeed}; 374 | /// # let mut termios = unsafe { mem::uninitialized() }; 375 | /// cfsetspeed(&mut termios, B9600).unwrap(); 376 | /// assert_eq!(cfgetispeed(&termios), B9600); 377 | /// assert_eq!(cfgetospeed(&termios), B9600); 378 | /// ``` 379 | /// 380 | /// # Portability 381 | /// 382 | /// This function is not part of the IEEE Std 1003.1 ("POSIX.1") specification, but it is available 383 | /// on Linux, BSD, and OS X. 384 | pub fn cfsetspeed(termios: &mut Termios, speed: speed_t) -> io::Result<()> { 385 | io_result(unsafe { ffi::cfsetspeed(termios.inner_mut(), speed) }) 386 | } 387 | 388 | /// Sets flags to disable all input and output processing. 389 | /// 390 | /// This function only sets the necessary values on the given `Termios` structure. The settings are 391 | /// applied on a successful call to [`tcsetattr()`](fn.tcsetattr.html). 392 | /// 393 | /// # Portability 394 | /// 395 | /// This function is not part of the IEEE Std 1003.1 ("POSIX.1") specification, but it is available 396 | /// on Linux, BSD, and OS X. 397 | pub fn cfmakeraw(termios: &mut Termios) { 398 | unsafe { ffi::cfmakeraw(termios.inner_mut()) }; 399 | } 400 | 401 | /// Blocks until all output written to the file descriptor is transmitted. 402 | /// 403 | /// # Parameters 404 | /// 405 | /// * `fd` should be an open file descriptor associated with a terminal. 406 | pub fn tcdrain(fd: RawFd) -> io::Result<()> { 407 | io_result(unsafe { ffi::tcdrain(fd) }) 408 | } 409 | 410 | /// Suspends or restarts transmission or reception of data. 411 | /// 412 | /// # Parameters 413 | /// 414 | /// * `fd` should be an open file descriptor associated with a terminal. 415 | /// * `action` should be one of the following constants: 416 | /// - `TCOOFF` suspends output. 417 | /// - `TCOON` restarts output. 418 | /// - `TCIOFF` transmits a STOP character, intended to cause the remote device to stop 419 | /// transmitting. 420 | /// - `TCION` transmits a START character, intended to cause the remote device to resume 421 | /// transmitting. 422 | pub fn tcflow(fd: RawFd, action: c_int) -> io::Result<()> { 423 | io_result(unsafe { ffi::tcflow(fd, action) }) 424 | } 425 | 426 | /// Discards data waiting in the terminal device's buffers. 427 | /// 428 | /// `tcflush()` discards data that has been written to the device by an application but has not yet 429 | /// been transmitted by the hardware or data that has been received by the hardware but has not yet 430 | /// been read by an application. 431 | /// 432 | /// # Parameters 433 | /// 434 | /// * `fd` should be an open file descriptor associated with a terminal. 435 | /// * `queue_selector` should be one of: 436 | /// - `TCIFLUSH` to discard data received but not read. 437 | /// - `TCOFLUSH` to discard data written but not transmitted. 438 | /// - `TCIOFLUSH` to discard both data received but not read and data written but not 439 | /// transmitted. 440 | pub fn tcflush(fd: RawFd, queue_selector: c_int) -> io::Result<()> { 441 | io_result(unsafe { ffi::tcflush(fd, queue_selector) }) 442 | } 443 | 444 | /// Populates a `Termios` structure with parameters associated with a terminal. 445 | /// 446 | /// Upon successful completion, the `Termios` structure referred to by the `termios` parameter will 447 | /// contain the parameters associated with the terminal device referred to by `fd`. 448 | /// 449 | /// # Parameters 450 | /// 451 | /// * `fd` should be an open file descriptor associated with a terminal. 452 | /// * `termios` should be a mutable reference to the `Termios` structure that will hold the 453 | /// terminal device's parameters. 454 | pub fn tcgetattr(fd: RawFd, termios: &mut Termios) -> io::Result<()> { 455 | io_result(unsafe { ffi::tcgetattr(fd, termios.inner_mut()) }) 456 | } 457 | 458 | /// Sets a terminal device's parameters. 459 | /// 460 | /// `tcsetattr()` returns successfully if it was able to perform any of the requested actions, even 461 | /// if other requested actions could not be performed. It will set all attributes that the 462 | /// implementation supports and leave others unchanged. The `Termios` structure will not be updated 463 | /// to reflect the changes that were applied. 464 | /// 465 | /// In order to determine which parameters were applied to the terminal device, an application 466 | /// should use [`tcgetattr()`](fn.tcgetattr.html) to obtain the latest state of the terminal 467 | /// device. In particular, when attempting to change baud rates, [`tcgetattr()`](fn.tcgetattr.html) 468 | /// can be used to determine which baud rates were actually selected. 469 | /// 470 | /// If none of the requested actions could be performed, then `tcsetattr()` returns an error. 471 | /// 472 | /// # Parameters 473 | /// 474 | /// * `fd` should be an open file descriptor associated with a terminal. 475 | /// * `action` should be one of the constants: 476 | /// - `TCSANOW` applies the change immediately. 477 | /// - `TCSADRAIN` applies the change after all output previously written to `fd` is transmitted. 478 | /// This mode should be used when changing parameters that affect output. 479 | /// - `TCSAFLUSH` applies the change after all output previously written to `fd` is transmitted. 480 | /// All data received but not read is discarded before applying the change. 481 | /// * `termios` should be a mutable reference to a `Termios` structure containing the parameters to 482 | /// apply to the terminal device. 483 | pub fn tcsetattr(fd: RawFd, action: c_int, termios: &Termios) -> io::Result<()> { 484 | io_result(unsafe { ffi::tcsetattr(fd, action, termios.inner()) }) 485 | } 486 | 487 | /// Returns the process group ID of the controlling terminal's session. 488 | /// 489 | /// # Parameters 490 | /// 491 | /// * `fd` should be an open file descriptor associated with a controlling terminal. 492 | pub fn tcgetsid(fd: RawFd) -> pid_t { 493 | unsafe { ffi::tcgetsid(fd) } 494 | } 495 | 496 | /// Transmits data to generate a break condition. 497 | /// 498 | /// If the terminal device is using asynchronous data transmission, `tcsendbreak()` transmits a 499 | /// continuous stream of zero bits for a specific duration. 500 | /// 501 | /// # Parameters 502 | /// 503 | /// * `fd` should be an open file descriptor associated with a terminal. 504 | /// * `duration` controls the duration of the transmitted zero bits. A value of 0 causes a 505 | /// transmission between 0.25 and 0.5 seconds. A value other than 0 causes a transmission for an 506 | /// implementation-defined period of time. 507 | pub fn tcsendbreak(fd: RawFd, duration: c_int) -> io::Result<()> { 508 | io_result(unsafe { ffi::tcsendbreak(fd, duration) }) 509 | } 510 | 511 | 512 | #[inline] 513 | fn io_result(result: c_int) -> io::Result<()> { 514 | match result { 515 | 0 => Ok(()), 516 | _ => Err(io::Error::last_os_error()) 517 | } 518 | } 519 | --------------------------------------------------------------------------------