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