From a9f2e9a9a7f861c9d51b82a6e40c23faeb063764 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Sat, 3 Mar 2018 20:48:37 -0700
Subject: [PATCH] Add template

---
 include/bits/wchar.h       |  7 +++++++
 platform/src/types.rs      |  1 +
 src/template/Cargo.toml    | 11 +++++++++++
 src/template/build.rs      | 11 +++++++++++
 src/template/cbindgen.toml |  6 ++++++
 src/template/src/lib.rs    | 14 ++++++++++++++
 6 files changed, 50 insertions(+)
 create mode 100644 include/bits/wchar.h
 create mode 100644 src/template/Cargo.toml
 create mode 100644 src/template/build.rs
 create mode 100644 src/template/cbindgen.toml
 create mode 100644 src/template/src/lib.rs

diff --git a/include/bits/wchar.h b/include/bits/wchar.h
new file mode 100644
index 00000000..98216dfb
--- /dev/null
+++ b/include/bits/wchar.h
@@ -0,0 +1,7 @@
+#ifndef _BITS_WCHAR_H
+#define _BITS_WCHAR_H
+
+typedef signed short wchar_t;
+typedef signed int wint_t;
+
+#endif /* _BITS_WCHAR_H */
diff --git a/platform/src/types.rs b/platform/src/types.rs
index bb87c740..dbbc2be3 100644
--- a/platform/src/types.rs
+++ b/platform/src/types.rs
@@ -43,6 +43,7 @@ pub type c_long = i64;
 pub type c_ulong = u64;
 
 pub type wchar_t = i16;
+pub type wint_t = i32;
 
 pub type off_t = c_long;
 pub type mode_t = u16;
diff --git a/src/template/Cargo.toml b/src/template/Cargo.toml
new file mode 100644
index 00000000..4021963f
--- /dev/null
+++ b/src/template/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "template"
+version = "0.1.0"
+authors = ["Jeremy Soller <jackpot51@gmail.com>"]
+build = "build.rs"
+
+[build-dependencies]
+cbindgen = { path = "../../cbindgen" }
+
+[dependencies]
+platform = { path = "../../platform" }
diff --git a/src/template/build.rs b/src/template/build.rs
new file mode 100644
index 00000000..35b5d3bd
--- /dev/null
+++ b/src/template/build.rs
@@ -0,0 +1,11 @@
+extern crate cbindgen;
+
+use std::{env, fs};
+
+fn main() {
+    let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
+    fs::create_dir_all("../../target/include").expect("failed to create include directory");
+    cbindgen::generate(crate_dir)
+      .expect("failed to generate bindings")
+      .write_to_file("../../target/include/template.h");
+}
diff --git a/src/template/cbindgen.toml b/src/template/cbindgen.toml
new file mode 100644
index 00000000..bf4ccefc
--- /dev/null
+++ b/src/template/cbindgen.toml
@@ -0,0 +1,6 @@
+sys_includes = []
+include_guard = "_TEMPLATE_H"
+language = "C"
+
+[enum]
+prefix_with_name = true
diff --git a/src/template/src/lib.rs b/src/template/src/lib.rs
new file mode 100644
index 00000000..e0c83c7c
--- /dev/null
+++ b/src/template/src/lib.rs
@@ -0,0 +1,14 @@
+//! template implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/template.h.html
+
+#![no_std]
+
+extern crate platform;
+
+use platform::types::*;
+
+/*
+#[no_mangle]
+pub extern "C" fn func(args) -> c_int {
+    unimplemented!();
+}
+*/
-- 
GitLab