Skip to content
Snippets Groups Projects
Commit c6a31f70 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Merge remote-tracking branch 'sajattack/master'

parents e1a8b288 22fb6c5b
No related branches found
No related tags found
No related merge requests found
...@@ -446,6 +446,7 @@ version = "0.1.0" ...@@ -446,6 +446,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"cbindgen 0.5.0", "cbindgen 0.5.0",
"platform 0.1.0", "platform 0.1.0",
"string 0.1.0",
"va_list 0.1.0", "va_list 0.1.0",
] ]
......
...@@ -10,3 +10,5 @@ cbindgen = { path = "../../cbindgen" } ...@@ -10,3 +10,5 @@ cbindgen = { path = "../../cbindgen" }
[dependencies] [dependencies]
platform = { path = "../platform" } platform = { path = "../platform" }
va_list = { path = "../../va_list", features = ["no_std"] } va_list = { path = "../../va_list", features = ["no_std"] }
string = { path = "../string" }
errno = { path = "../errno"}
...@@ -4,10 +4,16 @@ ...@@ -4,10 +4,16 @@
extern crate platform; extern crate platform;
extern crate va_list as vl; extern crate va_list as vl;
extern crate string;
extern crate errno;
use core::slice; use core::str;
use core::fmt::Write;
use platform::types::*; use platform::types::*;
use platform::c_str;
use platform::errno;
use errno::STR_ERROR;
use vl::VaList as va_list; use vl::VaList as va_list;
mod printf; mod printf;
...@@ -203,8 +209,23 @@ pub extern "C" fn pclose(stream: *mut FILE) -> c_int { ...@@ -203,8 +209,23 @@ pub extern "C" fn pclose(stream: *mut FILE) -> c_int {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn perror(s: *const c_char) { pub unsafe extern "C" fn perror(s: *const c_char) {
unimplemented!(); let mut buf: [u8; 256] = [0; 256];
let mut sw = platform::StringWriter(buf.as_mut_ptr(), buf.len());
if errno >= 0 && errno < STR_ERROR.len() as c_int {
sw.write_str(STR_ERROR[errno as usize]);
} else {
sw.write_fmt(format_args!("Unknown error {}", errno));
}
let mut w = platform::FileWriter(2);
w.write_fmt(format_args!(
"{}: {}\n",
str::from_utf8_unchecked(c_str(s)),
str::from_utf8_unchecked(c_str(buf.as_mut_ptr() as *mut c_char))
));
} }
#[no_mangle] #[no_mangle]
......
...@@ -6,4 +6,5 @@ ...@@ -6,4 +6,5 @@
int main(int argc, char** argv) { int main(int argc, char** argv) {
chdir("nonexistent"); chdir("nonexistent");
printf("errno: %d = %s\n", errno, strerror(errno)); printf("errno: %d = %s\n", errno, strerror(errno));
perror("perror");
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment