mirror of
https://github.com/uutils/coreutils
synced 2024-10-02 22:13:37 +00:00
uucore: read from sys:uname on Redox
This commit is contained in:
parent
8ba5fae6e3
commit
15aaa8215e
10
Cargo.toml
10
Cargo.toml
|
@ -83,14 +83,14 @@ generic = [
|
|||
"tail",
|
||||
"test",
|
||||
"whoami",
|
||||
"redox"
|
||||
"redox_generic"
|
||||
]
|
||||
# Feature "redox" contains the exclusive list of utilities
|
||||
# Feature "redox"/"redox_generic" contains the exclusive list of utilities
|
||||
# that can be compiled and run on redox. Should be built
|
||||
# with --no-default-features when selecting this feature.
|
||||
# TODO: merge with "generic" to avoid duplication once we support
|
||||
# all utilities in that feature.
|
||||
redox = [
|
||||
redox_generic = [
|
||||
|
||||
# And maybe all generic utilities
|
||||
"base32",
|
||||
|
@ -140,6 +140,10 @@ redox = [
|
|||
"wc",
|
||||
"yes",
|
||||
]
|
||||
redox = [
|
||||
"uname",
|
||||
"redox_generic"
|
||||
]
|
||||
test_unimplemented = []
|
||||
nightly = []
|
||||
default = ["generic", "unix"]
|
||||
|
|
2
build.rs
2
build.rs
|
@ -16,7 +16,7 @@ pub fn main() {
|
|||
if val == "1" && key.starts_with(feature_prefix) {
|
||||
let krate = key[feature_prefix.len()..].to_lowercase();
|
||||
match krate.as_ref() {
|
||||
"default" | "unix" | "redox" | "fuchsia" | "generic" | "nightly" | "test_unimplemented" => continue,
|
||||
"default" | "unix" | "redox" | "redox_generic" | "fuchsia" | "generic" | "nightly" | "test_unimplemented" => continue,
|
||||
_ => {},
|
||||
}
|
||||
crates.push(krate.to_string());
|
||||
|
|
|
@ -18,33 +18,35 @@ extern crate clap;
|
|||
use clap::{Arg, App};
|
||||
use uucore::utsname::Uname;
|
||||
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
static ABOUT: &'static str = "Print certain system information. With no OPTION, same as -s.";
|
||||
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
const ABOUT: &'static str = "Print certain system information. With no OPTION, same as -s.";
|
||||
|
||||
static OPT_ALL: &'static str = "all";
|
||||
static OPT_KERNELNAME: &'static str = "kernel-name";
|
||||
static OPT_NODENAME: &'static str = "nodename";
|
||||
static OPT_KERNELVERSION: &'static str = "kernel-version";
|
||||
static OPT_KERNELRELEASE: &'static str = "kernel-release";
|
||||
static OPT_MACHINE: &'static str = "machine";
|
||||
const OPT_ALL: &'static str = "all";
|
||||
const OPT_KERNELNAME: &'static str = "kernel-name";
|
||||
const OPT_NODENAME: &'static str = "nodename";
|
||||
const OPT_KERNELVERSION: &'static str = "kernel-version";
|
||||
const OPT_KERNELRELEASE: &'static str = "kernel-release";
|
||||
const OPT_MACHINE: &'static str = "machine";
|
||||
|
||||
//FIXME: unimplemented options
|
||||
//static OPT_PROCESSOR: &'static str = "processor";
|
||||
//static OPT_HWPLATFORM: &'static str = "hardware-platform";
|
||||
static OPT_OS: &'static str = "operating-system";
|
||||
//const OPT_PROCESSOR: &'static str = "processor";
|
||||
//const OPT_HWPLATFORM: &'static str = "hardware-platform";
|
||||
const OPT_OS: &'static str = "operating-system";
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
static HOST_OS: &'static str = "GNU/Linux";
|
||||
const HOST_OS: &'static str = "GNU/Linux";
|
||||
#[cfg(target_os = "windows")]
|
||||
static HOST_OS: &'static str = "Windows NT";
|
||||
const HOST_OS: &'static str = "Windows NT";
|
||||
#[cfg(target_os = "freebsd")]
|
||||
static HOST_OS: &'static str = "FreeBSD";
|
||||
const HOST_OS: &'static str = "FreeBSD";
|
||||
#[cfg(target_os = "openbsd")]
|
||||
static HOST_OS: &'static str = "OpenBSD";
|
||||
const HOST_OS: &'static str = "OpenBSD";
|
||||
#[cfg(target_os = "macos")]
|
||||
static HOST_OS: &'static str = "Darwin";
|
||||
const HOST_OS: &'static str = "Darwin";
|
||||
#[cfg(target_os = "fuchsia")]
|
||||
static HOST_OS: &'static str = "Fuchsia";
|
||||
const HOST_OS: &'static str = "Fuchsia";
|
||||
#[cfg(target_os = "redox")]
|
||||
const HOST_OS: &'static str = "Redox";
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
|
||||
|
|
|
@ -94,3 +94,62 @@ mod platform {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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())
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue