diff options
Diffstat (limited to 'src/sys/utsname.rs')
-rw-r--r-- | src/sys/utsname.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/sys/utsname.rs b/src/sys/utsname.rs index ce76a3be..528b7766 100644 --- a/src/sys/utsname.rs +++ b/src/sys/utsname.rs @@ -1,6 +1,7 @@ use std::mem; -use std::c_str::CString; use libc::{c_char}; +use std::ffi::{c_str_to_bytes_with_nul}; +use std::str::from_utf8_unchecked; mod ffi { use libc::c_int; @@ -29,23 +30,23 @@ pub struct UtsName { impl UtsName { pub fn sysname<'a>(&'a self) -> &'a str { - to_str(&self.sysname as *const c_char) + to_str(&(&self.sysname as *const c_char ) as *const *const c_char) } pub fn nodename<'a>(&'a self) -> &'a str { - to_str(&self.nodename as *const c_char) + to_str(&(&self.nodename as *const c_char ) as *const *const c_char) } pub fn release<'a>(&'a self) -> &'a str { - to_str(&self.release as *const c_char) + to_str(&(&self.release as *const c_char ) as *const *const c_char) } pub fn version<'a>(&'a self) -> &'a str { - to_str(&self.version as *const c_char) + to_str(&(&self.version as *const c_char ) as *const *const c_char) } pub fn machine<'a>(&'a self) -> &'a str { - to_str(&self.machine as *const c_char) + to_str(&(&self.machine as *const c_char ) as *const *const c_char) } } @@ -58,9 +59,9 @@ pub fn uname() -> UtsName { } #[inline] -fn to_str<'a>(s: *const c_char) -> &'a str { +fn to_str<'a>(s: *const *const c_char) -> &'a str { unsafe { - let res = CString::new(s, false); - mem::transmute(res.as_str().expect("[BUG] uname field not UTF-8")) + let res = c_str_to_bytes_with_nul(mem::transmute(s)); + from_utf8_unchecked(res) } } |