diff --git a/Cargo.lock b/Cargo.lock index 24e95adbbf64f692eb0734859233a011fcae6f29..d64703e038114b07833ed15774968fead0622619 100644 --- a/Cargo.lock +++ b/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" diff --git a/Cargo.toml b/Cargo.toml index 15ad2717e7ad6b06ba0bd9b545a9660554920bd4..34453157f39b9c2f23a275075e986337b05b9ad1 100644 --- a/Cargo.toml +++ b/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" } diff --git a/include/bits/stdio.h b/include/bits/stdio.h new file mode 100644 index 0000000000000000000000000000000000000000..1d9815ce289bc174383edbce0412a9a2a225051c --- /dev/null +++ b/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 */ diff --git a/include/stdarg.h b/include/stdarg.h new file mode 100644 index 0000000000000000000000000000000000000000..809114e57fd4bbd690292e39b23c31d15f9019b6 --- /dev/null +++ b/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 */ diff --git a/src/lib.rs b/src/lib.rs index 5eda04b6e8575b338f54a25dc0be0055718c5722..cdbf7bc9a0776db2215a0c1b03de14aa8194821b 100644 --- a/src/lib.rs +++ b/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; diff --git a/stdio/Cargo.toml b/stdio/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..aa996191f948f7ac00a7a34839ff2fa50df67911 --- /dev/null +++ b/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" } diff --git a/stdio/build.rs b/stdio/build.rs new file mode 100644 index 0000000000000000000000000000000000000000..f79b6f43bcb2883f348c5fcb947d456f82862d56 --- /dev/null +++ b/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"); +} diff --git a/stdio/cbindgen.toml b/stdio/cbindgen.toml new file mode 100644 index 0000000000000000000000000000000000000000..41dd92770ed13d876a71f06e9102af3d94a4ce60 --- /dev/null +++ b/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 diff --git a/stdio/src/lib.rs b/stdio/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..b2e0ea5bc0ca979b4703aa956a11661f22291985 --- /dev/null +++ b/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!(); +} +*/