simple pty

Change-Id: I3d7e2156eb3ea3961656c63dd26938071fc7645e
diff --git a/public/rust/crates/fuchsia-device/Cargo.toml b/public/rust/crates/fuchsia-device/Cargo.toml
new file mode 100644
index 0000000..44e776c
--- /dev/null
+++ b/public/rust/crates/fuchsia-device/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "fuchsia-device"
+version = "0.1.0"
+authors = ["Benjamin Brittain <bwb@google.com>"]
+
+[dependencies]
+fuchsia-zircon = "0.3"
+fdio = "0.2"
+failure = "0.1"
diff --git a/public/rust/crates/fuchsia-device/src/lib.rs b/public/rust/crates/fuchsia-device/src/lib.rs
new file mode 100644
index 0000000..0d193a1
--- /dev/null
+++ b/public/rust/crates/fuchsia-device/src/lib.rs
@@ -0,0 +1,16 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+//! Type-safe bindings for Zircon kernel
+//! [syscalls](https://fuchsia.googlesource.com/zircon/+/master/docs/syscalls.md).
+
+#![deny(warnings)]
+#![allow(dead_code)]
+extern crate fuchsia_zircon as zx;
+#[macro_use]
+extern crate fdio;
+#[macro_use]
+extern crate failure;
+
+pub mod pty;
diff --git a/public/rust/crates/fuchsia-device/src/pty.rs b/public/rust/crates/fuchsia-device/src/pty.rs
new file mode 100644
index 0000000..6e5471a
--- /dev/null
+++ b/public/rust/crates/fuchsia-device/src/pty.rs
@@ -0,0 +1,61 @@
+use fdio::{fdio_sys, ioctl_raw};
+use std::os::raw;
+use failure::Error;
+//use std::ffi::OsString;
+//use std::fs::{OpenOptions};
+// use zx::{self, Handle};
+
+const PTY_EVENT_HANGUP: u8 = 1;
+const PTY_EVENT_INTERRUPT: u8 = 2;
+const PTY_EVENT_SUSPEND: u8 = 4;
+const PTY_EVENT_MASK: u8 = 7;
+
+
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct pty_clr_set_t {
+    pub clr: u32,
+    pub set: u32,
+}
+
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct pty_window_size_t {
+    pub width: u32,
+    pub height: u32,
+}
+
+
+pub fn get_window_size() -> Result<pty_window_size_t, Error> {
+    let window = pty_window_size_t {
+        width: 0,
+        height: 0,
+    };
+
+    let success = unsafe {
+        ioctl_raw(0,
+              IOCTL_PTY_GET_WINDOW_SIZE,
+              ::std::ptr::null_mut() as *mut raw::c_void,
+              0,
+              &window as *const _ as *mut raw::c_void,
+              ::std::mem::size_of::<pty_window_size_t>())
+    };
+
+    if success < 0 {
+        Err(format_err!("get_window_size Ioctl failure"))
+    } else {
+        Ok(window)
+    }
+}
+
+const IOCTL_PTY_GET_WINDOW_SIZE: raw::c_int = make_ioctl!(
+    fdio_sys::IOCTL_KIND_DEFAULT,
+    fdio_sys::IOCTL_FAMILY_PTY,
+    0x01
+);
+
+const IOCTL_PTY_SET_WINDOW_SIZE: raw::c_int = make_ioctl!(
+    fdio_sys::IOCTL_KIND_DEFAULT,
+    fdio_sys::IOCTL_FAMILY_PTY,
+    0x20
+);