summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorRick Richardson <rrichardson@12sidedtech.com>2015-01-07 13:55:12 -0500
committerRick Richardson <rrichardson@12sidedtech.com>2015-01-07 13:55:12 -0500
commit1f99a9321946db0c79a805caa95e7cc2fe310f25 (patch)
treed63778829e1b402d44fb10146526c61a6b51e8b7 /src/sys
parentd6d31c25c8c585d828d4bf20bc739b494497c0c6 (diff)
downloadnix-1f99a9321946db0c79a805caa95e7cc2fe310f25.zip
more cstr fallout
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/utsname.rs19
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)
}
}