|
@@ -4,10 +4,13 @@
|
|
|
|
|
|
extern crate platform;
|
|
|
extern crate va_list as vl;
|
|
|
+extern crate string;
|
|
|
|
|
|
-use core::slice;
|
|
|
+use core::str;
|
|
|
+use core::fmt::Write;
|
|
|
|
|
|
use platform::types::*;
|
|
|
+use platform::c_str;
|
|
|
use vl::VaList as va_list;
|
|
|
|
|
|
mod printf;
|
|
@@ -201,8 +204,14 @@ pub extern "C" fn pclose(stream: *mut FILE) -> c_int {
|
|
|
}
|
|
|
|
|
|
#[no_mangle]
|
|
|
-pub extern "C" fn perror(s: *const c_char) {
|
|
|
- unimplemented!();
|
|
|
+pub unsafe extern "C" fn perror(s: *const c_char) {
|
|
|
+ let strerror = string::strerror(platform::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(strerror))
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
#[no_mangle]
|