From 94cf66b9fbca3fee55a7dfa31fc2201b761ac6cb Mon Sep 17 00:00:00 2001
From: Nikolay Korotkiy <sikmir@gmail.com>
Date: Thu, 20 Jun 2019 12:10:22 +0300
Subject: Add Haiku support


diff --git a/termios-0.3.1/src/os/haiku.rs b/termios-0.3.1/src/os/haiku.rs
new file mode 100644
index 0000000..12dbcc8
--- /dev/null
+++ b/termios-0.3.1/src/os/haiku.rs
@@ -0,0 +1,157 @@
+#![allow(non_camel_case_types)]
+
+use libc::{c_int,c_uint,c_uchar};
+
+pub type cc_t = c_uchar;
+pub type speed_t = c_uchar;
+pub type tcflag_t = c_uint;
+
+#[derive(Debug,Copy,Clone,Eq,PartialEq)]
+#[repr(C)]
+pub struct termios {
+    pub c_iflag: tcflag_t,
+    pub c_oflag: tcflag_t,
+    pub c_cflag: tcflag_t,
+    pub c_lflag: tcflag_t,
+    c_line: cc_t,
+    c_ispeed: speed_t,
+    c_ospeed: speed_t,
+    pub c_cc: [cc_t; NCCS]
+}
+
+pub const NCCS: usize = 11;
+
+// c_cc characters
+pub const VINTR:    usize = 0;
+pub const VQUIT:    usize = 1;
+pub const VERASE:   usize = 2;
+pub const VKILL:    usize = 3;
+pub const VEOF:     usize = 4;
+pub const VEOL:     usize = 5;
+pub const VMIN:     usize = 4;
+pub const VTIME:    usize = 5;
+pub const VEOL2:    usize = 6;
+pub const VSWTCH:   usize = 7;
+pub const VSTART:   usize = 8;
+pub const VSTOP:    usize = 9;
+pub const VSUSP:    usize = 10;
+
+// c_iflag bits
+pub const IGNBRK:  tcflag_t = 0x01;
+pub const BRKINT:  tcflag_t = 0x02;
+pub const IGNPAR:  tcflag_t = 0x04;
+pub const PARMRK:  tcflag_t = 0x08;
+pub const INPCK:   tcflag_t = 0x10;
+pub const ISTRIP:  tcflag_t = 0x20;
+pub const INLCR:   tcflag_t = 0x40;
+pub const IGNCR:   tcflag_t = 0x80;
+pub const ICRNL:   tcflag_t = 0x100;
+pub const IUCLC:   tcflag_t = 0x200;
+pub const IXON:    tcflag_t = 0x400;
+pub const IXANY:   tcflag_t = 0x800;
+pub const IXOFF:   tcflag_t = 0x1000;
+
+// c_oflag bits
+pub const OPOST:  tcflag_t = 0x01;
+pub const OLCUC:  tcflag_t = 0x02;
+pub const ONLCR:  tcflag_t = 0x04;
+pub const OCRNL:  tcflag_t = 0x08;
+pub const ONOCR:  tcflag_t = 0x10;
+pub const ONLRET: tcflag_t = 0x20;
+pub const OFILL:  tcflag_t = 0x40;
+pub const OFDEL:  tcflag_t = 0x80;
+pub const NLDLY:  tcflag_t = 0x100;
+pub const NL0:    tcflag_t = 0x000;
+pub const NL1:    tcflag_t = 0x100;
+pub const CRDLY:  tcflag_t = 0x600;
+pub const CR0:    tcflag_t = 0x000;
+pub const CR1:    tcflag_t = 0x200;
+pub const CR2:    tcflag_t = 0x400;
+pub const CR3:    tcflag_t = 0x600;
+pub const TABDLY: tcflag_t = 0x1800;
+pub const TAB0:   tcflag_t = 0x0000;
+pub const TAB1:   tcflag_t = 0x0800;
+pub const TAB2:   tcflag_t = 0x1000;
+pub const TAB3:   tcflag_t = 0x1800;
+pub const BSDLY:  tcflag_t = 0x2000;
+pub const BS0:    tcflag_t = 0x0000;
+pub const BS1:    tcflag_t = 0x2000;
+pub const VTDLY:  tcflag_t = 0x4000;
+pub const VT0:    tcflag_t = 0x0000;
+pub const VT1:    tcflag_t = 0x4000;
+pub const FFDLY:  tcflag_t = 0x8000;
+pub const FF0:    tcflag_t = 0x0000;
+pub const FF1:    tcflag_t = 0x8000;
+
+// c_cflag bits
+pub const CBAUD:    tcflag_t = 0x1F;
+pub const CSIZE:    tcflag_t = 0x20;
+pub const CS5:      tcflag_t = 0x00;
+pub const CS6:      tcflag_t = 0x00;
+pub const CS7:      tcflag_t = 0x00;
+pub const CS8:      tcflag_t = 0x20;
+pub const CSTOPB:   tcflag_t = 0x40;
+pub const CREAD:    tcflag_t = 0x80;
+pub const PARENB:   tcflag_t = 0x100;
+pub const PARODD:   tcflag_t = 0x200;
+pub const HUPCL:    tcflag_t = 0x400;
+pub const CLOCAL:   tcflag_t = 0x800;
+pub const XLOBLK:   tcflag_t = 0x1000;
+pub const CTSFLOW:  tcflag_t = 0x2000;
+pub const RTSFLOW:  tcflag_t = 0x4000;
+pub const CRTSCTS:  tcflag_t = 0x6000;
+
+// c_lflag bits
+pub const ISIG:    tcflag_t = 0x01;
+pub const ICANON:  tcflag_t = 0x02;
+pub const XCASE:   tcflag_t = 0x04;
+pub const ECHO:    tcflag_t = 0x08;
+pub const ECHOE:   tcflag_t = 0x10;
+pub const ECHOK:   tcflag_t = 0x20;
+pub const ECHONL:  tcflag_t = 0x40;
+pub const NOFLSH:  tcflag_t = 0x80;
+pub const TOSTOP:  tcflag_t = 0x100;
+pub const IEXTEN:  tcflag_t = 0x200;
+pub const ECHOCTL: tcflag_t = 0x400;
+pub const ECHOPRT: tcflag_t = 0x800;
+pub const ECHOKE:  tcflag_t = 0x1000;
+pub const FLUSHO:  tcflag_t = 0x2000;
+pub const PENDIN:  tcflag_t = 0x4000;
+
+// baud rates
+pub const B0:       speed_t = 0x00;
+pub const B50:      speed_t = 0x01;
+pub const B75:      speed_t = 0x02;
+pub const B110:     speed_t = 0x03;
+pub const B134:     speed_t = 0x04;
+pub const B150:     speed_t = 0x05;
+pub const B200:     speed_t = 0x06;
+pub const B300:     speed_t = 0x07;
+pub const B600:     speed_t = 0x08;
+pub const B1200:    speed_t = 0x09;
+pub const B1800:    speed_t = 0x0A;
+pub const B2400:    speed_t = 0x0B;
+pub const B4800:    speed_t = 0x0C;
+pub const B9600:    speed_t = 0x0D;
+pub const B19200:   speed_t = 0x0E;
+pub const B38400:   speed_t = 0x0F;
+pub const B57600:   speed_t = 0x10;
+pub const B115200:  speed_t = 0x11;
+pub const B230400:  speed_t = 0x12;
+pub const B31250:   speed_t = 0x13;
+
+// tcsetattr()
+pub const TCSANOW:   c_int = 0x01;
+pub const TCSADRAIN: c_int = 0x02;
+pub const TCSAFLUSH: c_int = 0x04;
+
+// tcflow()
+pub const TCOOFF: c_int = 0x01;
+pub const TCOON:  c_int = 0x02;
+pub const TCIOFF: c_int = 0x04;
+pub const TCION:  c_int = 0x08;
+
+// tcflush()
+pub const TCIFLUSH:  c_int = 0x01;
+pub const TCOFLUSH:  c_int = 0x02;
+pub const TCIOFLUSH: c_int = 0x03;
diff --git a/termios-0.3.1/src/os/mod.rs b/termios-0.3.1/src/os/mod.rs
index 519723c..af8f5be 100644
--- a/termios-0.3.1/src/os/mod.rs
+++ b/termios-0.3.1/src/os/mod.rs
@@ -6,6 +6,7 @@
 #[cfg(target_os = "freebsd")] pub use self::freebsd as target;
 #[cfg(target_os = "openbsd")] pub use self::openbsd as target;
 #[cfg(target_os = "dragonfly")] pub use self::dragonfly as target;
+#[cfg(target_os = "haiku")] pub use self::haiku as target;
 
 #[cfg(target_os = "linux")] pub mod linux;
 #[cfg(target_os = "android")] pub mod android;
@@ -13,3 +14,4 @@
 #[cfg(target_os = "freebsd")] pub mod freebsd;
 #[cfg(target_os = "openbsd")] pub mod openbsd;
 #[cfg(target_os = "dragonfly")] pub mod dragonfly;
+#[cfg(target_os = "haiku")] pub mod haiku;
-- 
2.21.0

From 66ac406b463a239019cbdf1abc8c50fd5e61db2d Mon Sep 17 00:00:00 2001
From: Crestwave <crestwave@users.noreply.github.com>
Date: Tue, 1 Oct 2019 08:44:17 +0000
Subject: Fix Haiku build


diff --git a/termios-0.3.1/src/ffi.rs b/termios-0.3.1/src/ffi.rs
index 89e2084..faf59d2 100644
--- a/termios-0.3.1/src/ffi.rs
+++ b/termios-0.3.1/src/ffi.rs
@@ -2,7 +2,7 @@
 
 use libc::{c_int,pid_t};
 
-#[link(name = "c")]
+#[cfg_attr(not(target_os = "haiku"), link(name = "c"))]
 extern "C" {
     pub fn tcgetattr(fd: c_int, termios_p: *mut ::os::target::termios) -> c_int;
     pub fn tcsetattr(fd: c_int, optional_actions: c_int, termios_p: *const ::os::target::termios) -> c_int;
-- 
2.23.0

From 5bf7c2c51d9461ea0667e46e2210ca36fcd01a8b Mon Sep 17 00:00:00 2001
From: Crestwave <crest.wave@yahoo.com>
Date: Mon, 7 Oct 2019 01:22:57 +0000
Subject: Fix tests on Haiku


diff --git a/termios-0.3.1/src/ffi.rs b/termios-0.3.1/src/ffi.rs
index faf59d2..7bd15ad 100644
--- a/termios-0.3.1/src/ffi.rs
+++ b/termios-0.3.1/src/ffi.rs
@@ -1,6 +1,8 @@
 //! Unsafe FFI bindings.
 
-use libc::{c_int,pid_t};
+use libc::c_int;
+#[cfg(not(target_os = "haiku"))]
+use libc::pid_t;
 
 #[cfg_attr(not(target_os = "haiku"), link(name = "c"))]
 extern "C" {
@@ -15,6 +17,8 @@ extern "C" {
     pub fn cfgetospeed(termios_p: *const ::os::target::termios) -> ::os::target::speed_t;
     pub fn cfsetispeed(termios_p: *mut ::os::target::termios, speed: ::os::target::speed_t) -> c_int;
     pub fn cfsetospeed(termios_p: *mut ::os::target::termios, speed: ::os::target::speed_t) -> c_int;
+    #[cfg(not(target_os = "haiku"))]
     pub fn cfsetspeed(termios_p: *mut ::os::target::termios, speed: ::os::target::speed_t) -> c_int;
+    #[cfg(not(target_os = "haiku"))]
     pub fn tcgetsid(fd: c_int) -> pid_t;
 }
diff --git a/termios-0.3.1/src/lib.rs b/termios-0.3.1/src/lib.rs
index d229427..4870118 100644
--- a/termios-0.3.1/src/lib.rs
+++ b/termios-0.3.1/src/lib.rs
@@ -76,6 +76,7 @@
 //! example of a portable function that sets the maximum speed on a `Termios` struct.
 //!
 //! ```no_run
+//! # #[cfg(not(target_os = "haiku"))] {
 //! use std::io;
 //! use termios::{Termios,cfsetspeed};
 //!
@@ -107,6 +108,7 @@
 //! # let fd = 1;
 //! let mut termios = Termios::from_fd(fd).unwrap();
 //! set_fastest_speed(&mut termios).unwrap();
+//! # }
 //! ```
 
 extern crate libc;
@@ -116,7 +118,9 @@ use std::mem;
 use std::ops::{Deref,DerefMut};
 use std::os::unix::io::RawFd;
 
-use libc::{c_int,pid_t};
+use libc::c_int;
+#[cfg(not(target_os = "haiku"))]
+use libc::pid_t;
 
 pub use ::os::target::{cc_t,speed_t,tcflag_t}; // types
 pub use ::os::target::{VEOF,VEOL,VERASE,VINTR,VKILL,VMIN,VQUIT,VSTART,VSTOP,VSUSP,VTIME}; // c_cc subscripts
@@ -161,6 +165,7 @@ pub mod os;
 ///     termios.c_cc[VMIN] = 0;
 ///     termios.c_cc[VTIME] = 0;
 ///
+///     #[cfg(not(target_os = "haiku"))]
 ///     try!(cfsetspeed(&mut termios, B9600));
 ///     try!(tcsetattr(fd, TCSANOW, &mut termios));
 ///
@@ -366,6 +371,7 @@ pub fn cfsetospeed(termios: &mut Termios, speed: speed_t) -> io::Result<()> {
 ///
 /// This function is not part of the IEEE Std 1003.1 ("POSIX.1") specification, but it is available
 /// on Linux, BSD, and OS X.
+#[cfg(not(target_os = "haiku"))]
 pub fn cfsetspeed(termios: &mut Termios, speed: speed_t) -> io::Result<()> {
     io_result(unsafe { ffi::cfsetspeed(termios.inner_mut(), speed) })
 }
@@ -474,6 +480,7 @@ pub fn tcsetattr(fd: RawFd, action: c_int, termios: &Termios) -> io::Result<()>
 /// # Parameters
 ///
 /// * `fd` should be an open file descriptor associated with a controlling terminal.
+#[cfg(not(target_os = "haiku"))]
 pub fn tcgetsid(fd: RawFd) -> pid_t {
     unsafe { ffi::tcgetsid(fd) }
 }
-- 
2.23.0

