From 18961114e2944cf2b3884861f72458d70a598ef5 Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jeremy@system76.com> Date: Thu, 8 Mar 2018 14:51:22 -0700 Subject: [PATCH] Simplify perror --- Cargo.lock | 2 +- src/stdio/Cargo.toml | 1 - src/stdio/src/lib.rs | 17 ++++------------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab929b2e..06030c19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -445,8 +445,8 @@ name = "stdio" version = "0.1.0" dependencies = [ "cbindgen 0.5.0", + "errno 0.1.0", "platform 0.1.0", - "string 0.1.0", "va_list 0.1.0", ] diff --git a/src/stdio/Cargo.toml b/src/stdio/Cargo.toml index 570e409b..2f53e58d 100644 --- a/src/stdio/Cargo.toml +++ b/src/stdio/Cargo.toml @@ -10,5 +10,4 @@ cbindgen = { path = "../../cbindgen" } [dependencies] platform = { path = "../platform" } va_list = { path = "../../va_list", features = ["no_std"] } -string = { path = "../string" } errno = { path = "../errno"} diff --git a/src/stdio/src/lib.rs b/src/stdio/src/lib.rs index 1f166000..83d44463 100644 --- a/src/stdio/src/lib.rs +++ b/src/stdio/src/lib.rs @@ -4,7 +4,6 @@ extern crate platform; extern crate va_list as vl; -extern crate string; extern crate errno; use core::str; @@ -210,22 +209,14 @@ pub extern "C" fn pclose(stream: *mut FILE) -> c_int { #[no_mangle] pub unsafe extern "C" fn perror(s: *const c_char) { - let mut buf: [u8; 256] = [0; 256]; - - let mut sw = platform::StringWriter(buf.as_mut_ptr(), buf.len()); + let s_str = str::from_utf8_unchecked(c_str(s)); + let mut w = platform::FileWriter(2); if errno >= 0 && errno < STR_ERROR.len() as c_int { - sw.write_str(STR_ERROR[errno as usize]); + w.write_fmt(format_args!("{}: {}\n", s_str, STR_ERROR[errno as usize])); } else { - sw.write_fmt(format_args!("Unknown error {}", errno)); + w.write_fmt(format_args!("{}: Unknown error {}\n", s_str, 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] -- GitLab