Browse Source

WIP: stdio.h

Jeremy Soller 7 years ago
parent
commit
e30dec7124
9 changed files with 80 additions and 0 deletions
  1. 9 0
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 13 0
      include/bits/stdio.h
  4. 9 0
      include/stdarg.h
  5. 1 0
      src/lib.rs
  6. 11 0
      stdio/Cargo.toml
  7. 11 0
      stdio/build.rs
  8. 7 0
      stdio/cbindgen.toml
  9. 18 0
      stdio/src/lib.rs

+ 9 - 0
Cargo.lock

@@ -199,6 +199,7 @@ dependencies = [
  "compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)",
  "fcntl 0.1.0",
  "platform 0.1.0",
+ "stdio 0.1.0",
  "string 0.1.0",
  "unistd 0.1.0",
 ]
@@ -365,6 +366,14 @@ dependencies = [
  "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "stdio"
+version = "0.1.0"
+dependencies = [
+ "cbindgen 0.5.0",
+ "platform 0.1.0",
+]
+
 [[package]]
 name = "string"
 version = "0.1.0"

+ 1 - 0
Cargo.toml

@@ -14,6 +14,7 @@ members = ["crt0"]
 compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins.git", default-features = false, features = ["mem"] }
 platform = { path = "platform" }
 fcntl = { path = "fcntl" }
+stdio = { path = "stdio" }
 string = { path = "string" }
 unistd = { path = "unistd" }
 

+ 13 - 0
include/bits/stdio.h

@@ -0,0 +1,13 @@
+#ifndef _BITS_STDIO_H
+#define _BITS_STDIO_H
+
+int printf(const char *restrict fmt, ...) {
+	int ret;
+	va_list ap;
+	va_start(ap, fmt);
+	ret = vfprintf(stdout, fmt, ap);
+	va_end(ap);
+	return ret;
+}
+
+#endif /* _BITS_STDIO_H */

+ 9 - 0
include/stdarg.h

@@ -0,0 +1,9 @@
+#ifndef _STDARG_H
+#define _STDARG_H
+
+#define va_start(v,l)   __builtin_va_start(v,l)
+#define va_end(v)       __builtin_va_end(v)
+#define va_arg(v,l)     __builtin_va_arg(v,l)
+#define va_copy(d,s) __builtin_va_copy(d,s)
+
+#endif /* _STDARG_H */

+ 1 - 0
src/lib.rs

@@ -5,6 +5,7 @@ extern crate compiler_builtins;
 extern crate platform;
 
 extern crate fcntl;
+extern crate stdio;
 extern crate string;
 extern crate unistd;
 

+ 11 - 0
stdio/Cargo.toml

@@ -0,0 +1,11 @@
+[package]
+name = "stdio"
+version = "0.1.0"
+authors = ["Jeremy Soller <jackpot51@gmail.com>"]
+build = "build.rs"
+
+[build-dependencies]
+cbindgen = { path = "../cbindgen" }
+
+[dependencies]
+platform = { path = "../platform" }

+ 11 - 0
stdio/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/stdio.h");
+}

+ 7 - 0
stdio/cbindgen.toml

@@ -0,0 +1,7 @@
+sys_includes = ["stdarg.h", "stddef.h"]
+include_guard = "_stdio_H"
+trailer = "#include <bits/stdio.h>"
+language = "C"
+
+[enum]
+prefix_with_name = true

+ 18 - 0
stdio/src/lib.rs

@@ -0,0 +1,18 @@
+//! stdio implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/stdio.h.html
+
+#![no_std]
+
+extern crate platform;
+
+use platform::types::*;
+
+pub const BUFSIZ: c_int = 4096;
+
+pub const FILENAME_MAX: c_int = 4096;
+
+/*
+#[no_mangle]
+pub extern "C" fn func(args) -> c_int {
+    unimplemented!();
+}
+*/