1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-05 07:27:46 +00:00

uucore: remove utsname.rs (and replace with platform-info)

This commit is contained in:
Alex Lyon 2018-03-11 18:48:47 -07:00 committed by Roy Ivy III
parent ca3393bd86
commit 1c0b1ab375
3 changed files with 1 additions and 160 deletions

View file

@ -8,7 +8,6 @@ getopts = "0.2.14"
time = { version = "0.1.38", optional = true } time = { version = "0.1.38", optional = true }
data-encoding = { version = "^1.1", optional = true } data-encoding = { version = "^1.1", optional = true }
libc = { version = "0.2.34", optional = true } libc = { version = "0.2.34", optional = true }
winapi = { version = "0.3", features = ["sysinfoapi"], optional = true }
[features] [features]
fs = ["libc"] fs = ["libc"]
@ -21,8 +20,7 @@ process = ["libc"]
signals = [] signals = []
entries = ["libc"] entries = ["libc"]
wide = [] wide = []
utsname = ["libc", "winapi"] default = ["fs", "libc", "utf8", "encoding", "parse_time", "mode", "utmpx", "process", "entries", "signals", "wide"]
default = ["fs", "libc", "utf8", "utsname", "encoding", "parse_time", "mode", "utmpx", "process", "entries", "signals", "wide"]
[lib] [lib]
path = "lib.rs" path = "lib.rs"

View file

@ -24,8 +24,6 @@ pub mod parse_time;
pub mod mode; pub mod mode;
#[cfg(all(unix, not(target_os = "fuchsia"), feature = "utmpx"))] #[cfg(all(unix, not(target_os = "fuchsia"), feature = "utmpx"))]
pub mod utmpx; pub mod utmpx;
#[cfg(feature = "utsname")]
pub mod utsname;
#[cfg(all(unix, feature = "entries"))] #[cfg(all(unix, feature = "entries"))]
pub mod entries; pub mod entries;
#[cfg(all(unix, feature = "process"))] #[cfg(all(unix, feature = "process"))]

View file

@ -1,155 +0,0 @@
// This file is part of the uutils coreutils package.
//
// (c) Jian Zeng <anonymousknight96 AT gmail.com>
//
// 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<Self> {
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<str> {
cstr2cow!(self.inner.sysname)
}
pub fn nodename(&self) -> Cow<str> {
cstr2cow!(self.inner.nodename)
}
pub fn release(&self) -> Cow<str> {
cstr2cow!(self.inner.release)
}
pub fn version(&self) -> Cow<str> {
cstr2cow!(self.inner.version)
}
pub fn machine(&self) -> Cow<str> {
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<Uname> {
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<str> {
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<Uname> {
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<str> {
Cow::from(self.kernel_name.as_str())
}
pub fn nodename(&self) -> Cow<str> {
Cow::from(self.nodename.as_str())
}
pub fn release(&self) -> Cow<str> {
Cow::from(self.kernel_release.as_str())
}
pub fn version(&self) -> Cow<str> {
Cow::from(self.kernel_version.as_str())
}
pub fn machine(&self) -> Cow<str> {
Cow::from(self.machine.as_str())
}
}
}