From 1c0b1ab3756e1d192497d72622db74378d2ee2dd Mon Sep 17 00:00:00 2001 From: Alex Lyon Date: Sun, 11 Mar 2018 18:48:47 -0700 Subject: [PATCH] uucore: remove utsname.rs (and replace with platform-info) --- src/uucore/Cargo.toml | 4 +- src/uucore/lib.rs | 2 - src/uucore/utsname.rs | 155 ------------------------------------------ 3 files changed, 1 insertion(+), 160 deletions(-) delete mode 100644 src/uucore/utsname.rs diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index 90be15c92..e1e56fed3 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -8,7 +8,6 @@ getopts = "0.2.14" time = { version = "0.1.38", optional = true } data-encoding = { version = "^1.1", optional = true } libc = { version = "0.2.34", optional = true } -winapi = { version = "0.3", features = ["sysinfoapi"], optional = true } [features] fs = ["libc"] @@ -21,8 +20,7 @@ process = ["libc"] signals = [] entries = ["libc"] wide = [] -utsname = ["libc", "winapi"] -default = ["fs", "libc", "utf8", "utsname", "encoding", "parse_time", "mode", "utmpx", "process", "entries", "signals", "wide"] +default = ["fs", "libc", "utf8", "encoding", "parse_time", "mode", "utmpx", "process", "entries", "signals", "wide"] [lib] path = "lib.rs" diff --git a/src/uucore/lib.rs b/src/uucore/lib.rs index 14c2246d4..dbbc1b825 100644 --- a/src/uucore/lib.rs +++ b/src/uucore/lib.rs @@ -24,8 +24,6 @@ pub mod parse_time; pub mod mode; #[cfg(all(unix, not(target_os = "fuchsia"), feature = "utmpx"))] pub mod utmpx; -#[cfg(feature = "utsname")] -pub mod utsname; #[cfg(all(unix, feature = "entries"))] pub mod entries; #[cfg(all(unix, feature = "process"))] diff --git a/src/uucore/utsname.rs b/src/uucore/utsname.rs deleted file mode 100644 index 16b94472a..000000000 --- a/src/uucore/utsname.rs +++ /dev/null @@ -1,155 +0,0 @@ -// This file is part of the uutils coreutils package. -// -// (c) Jian Zeng -// -// For the full copyright and license information, please view the LICENSE file -// that was distributed with this source code. -// - -pub use self::platform::*; - -#[cfg(unix)] -mod platform { - use ::libc::{uname, utsname}; - use ::std::mem; - use ::std::ffi::CStr; - use ::std::borrow::Cow; - use ::std::io; - - macro_rules! cstr2cow { - ($v:expr) => ( - unsafe { CStr::from_ptr($v.as_ref().as_ptr()).to_string_lossy() } - ) - } - - pub struct Uname { - inner: utsname, - } - - impl Uname { - pub fn new() -> io::Result { - unsafe { - let mut uts: utsname = mem::uninitialized(); - if uname(&mut uts) == 0 { - Ok(Uname { inner: uts }) - } else { - Err(io::Error::last_os_error()) - } - } - } - - pub fn sysname(&self) -> Cow { - cstr2cow!(self.inner.sysname) - } - - pub fn nodename(&self) -> Cow { - cstr2cow!(self.inner.nodename) - } - - pub fn release(&self) -> Cow { - cstr2cow!(self.inner.release) - } - - pub fn version(&self) -> Cow { - cstr2cow!(self.inner.version) - } - - pub fn machine(&self) -> Cow { - cstr2cow!(self.inner.machine) - } - } -} - -#[cfg(windows)] -mod platform { - use ::winapi::um::sysinfoapi::{SYSTEM_INFO, GetSystemInfo}; - use ::winapi::um::winnt::*; - use ::std::mem; - use ::std::borrow::Cow; - use ::std::io; - - pub struct Uname { - inner: SYSTEM_INFO - } - - impl Uname { - pub fn new() -> io::Result { - unsafe { - let mut info = mem::uninitialized(); - GetSystemInfo(&mut info); - Ok(Uname { inner: info }) - } - } - - // FIXME: need to implement more architectures (e.g. ARM) - pub fn machine(&self) -> Cow { - let arch = unsafe { - match self.inner.u.s().wProcessorArchitecture { - PROCESSOR_ARCHITECTURE_AMD64 => "x86_64", - PROCESSOR_ARCHITECTURE_INTEL => "x86", - _ => unimplemented!() - } - }; - Cow::from(arch) - } - } -} - -#[cfg(target_os = "redox")] -mod platform { - use ::std::borrow::Cow; - use ::std::io::{self, Read}; - use ::std::fs::File; - - pub struct Uname { - kernel_name: String, - nodename: String, - kernel_release: String, - kernel_version: String, - machine: String - } - - impl Uname { - pub fn new() -> io::Result { - let mut inner = String::new(); - File::open("sys:uname")?.read_to_string(&mut inner)?; - - let mut lines = inner.lines(); - - let kernel_name = lines.next().unwrap(); - let nodename = lines.next().unwrap(); - let kernel_release = lines.next().unwrap(); - let kernel_version = lines.next().unwrap(); - let machine = lines.next().unwrap(); - - // FIXME: don't actually duplicate the data as doing so is wasteful - Ok(Uname { - kernel_name: kernel_name.to_owned(), - nodename: nodename.to_owned(), - kernel_release: kernel_release.to_owned(), - kernel_version: kernel_version.to_owned(), - machine: machine.to_owned() - }) - } - - pub fn sysname(&self) -> Cow { - Cow::from(self.kernel_name.as_str()) - } - - pub fn nodename(&self) -> Cow { - Cow::from(self.nodename.as_str()) - } - - pub fn release(&self) -> Cow { - Cow::from(self.kernel_release.as_str()) - } - - pub fn version(&self) -> Cow { - Cow::from(self.kernel_version.as_str()) - } - - pub fn machine(&self) -> Cow { - Cow::from(self.machine.as_str()) - } - } -} \ No newline at end of file