From fc767fd0a8a19e86b1a1364dd3790350e9284800 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Wed, 3 May 2017 21:05:34 -0600
Subject: [PATCH] Fixes for Linux

---
 src/terminal/main.rs | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/terminal/main.rs b/src/terminal/main.rs
index 6b0d59f..9ea2e4e 100644
--- a/src/terminal/main.rs
+++ b/src/terminal/main.rs
@@ -26,6 +26,33 @@ use getpty::getpty;
 mod console;
 mod getpty;
 
+#[cfg(not(target_os="redox"))]
+fn slave_stdio(tty_path: &str) -> Result<(File, File, File)> {
+    use io::Error;
+    use libc::{O_RDONLY, O_WRONLY};
+    use std::ffi::CString;
+
+    let cvt = |res: i32| -> Result<i32> {
+        if res < 0 {
+            Err(Error::last_os_error())
+        } else {
+            Ok(res)
+        }
+    };
+
+    let tty_c = CString::new(tty_path).unwrap();
+    let stdin = unsafe { File::from_raw_fd(
+        cvt(libc::open(tty_c.as_ptr(), O_RDONLY))?
+    ) };
+    let stdout = unsafe { File::from_raw_fd(
+        cvt(libc::open(tty_c.as_ptr(), O_WRONLY))?
+    ) };
+    let stderr = unsafe { File::from_raw_fd(
+        cvt(libc::open(tty_c.as_ptr(), O_WRONLY))?
+    ) };
+    Ok((stdin, stdout, stderr))
+}
+
 #[cfg(target_os="redox")]
 fn slave_stdio(tty_path: &str) -> Result<(File, File, File)> {
     use io::Error;
-- 
GitLab