summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBryant Mairs <bryant@mai.rs>2017-08-09 22:36:31 -0700
committerBryant Mairs <bryant@mai.rs>2017-08-16 19:36:51 -0700
commit3cd785c492a4de625ded3c1fd2bdaf1822d68297 (patch)
treeabe0ac20eaaf800ee86672bd22b24d23b6c27494 /src
parent5515a5cc6e46b1046cad414b27aa1edfcbde4f9d (diff)
downloadnix-3cd785c492a4de625ded3c1fd2bdaf1822d68297.zip
Use libc::uname and libc::utsname
Diffstat (limited to 'src')
-rw-r--r--src/sys/utsname.rs39
1 files changed, 9 insertions, 30 deletions
diff --git a/src/sys/utsname.rs b/src/sys/utsname.rs
index 7eeb323b..104249d8 100644
--- a/src/sys/utsname.rs
+++ b/src/sys/utsname.rs
@@ -1,62 +1,41 @@
use std::mem;
-use libc::{c_char};
+use libc::{self, c_char};
use std::ffi::CStr;
-use std::str::from_utf8_unchecked;
-
-mod ffi {
- use libc::c_int;
- use super::UtsName;
-
- extern {
- pub fn uname(buf: *mut UtsName) -> c_int;
- }
-}
-
-
-const UTSNAME_LEN: usize = 65;
+use std::str::from_utf8_unchecked;
#[repr(C)]
#[derive(Copy)]
-pub struct UtsName {
- sysname: [c_char; UTSNAME_LEN],
- nodename: [c_char; UTSNAME_LEN],
- release: [c_char; UTSNAME_LEN],
- version: [c_char; UTSNAME_LEN],
- machine: [c_char; UTSNAME_LEN],
- // ifdef _GNU_SOURCE
- #[allow(dead_code)]
- domainname: [c_char; UTSNAME_LEN]
-}
+pub struct UtsName(libc::utsname);
// workaround for `derive(Clone)` not working for fixed-length arrays
impl Clone for UtsName { fn clone(&self) -> UtsName { *self } }
impl UtsName {
pub fn sysname<'a>(&'a self) -> &'a str {
- to_str(&(&self.sysname as *const c_char ) as *const *const c_char)
+ to_str(&(&self.0.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 ) as *const *const c_char)
+ to_str(&(&self.0.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 ) as *const *const c_char)
+ to_str(&(&self.0.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 ) as *const *const c_char)
+ to_str(&(&self.0.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 ) as *const *const c_char)
+ to_str(&(&self.0.machine as *const c_char ) as *const *const c_char)
}
}
pub fn uname() -> UtsName {
unsafe {
let mut ret: UtsName = mem::uninitialized();
- ffi::uname(&mut ret as *mut UtsName);
+ libc::uname(&mut ret.0);
ret
}
}