mirror of
https://github.com/uutils/coreutils
synced 2025-01-19 00:24:13 +00:00
commit
14af4c38a0
6 changed files with 136 additions and 0 deletions
35
Cargo.lock
generated
35
Cargo.lock
generated
|
@ -3,6 +3,7 @@ name = "uutils"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"aho-corasick 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"arch 0.0.1",
|
||||
"base64 0.0.1",
|
||||
"basename 0.0.1",
|
||||
"cat 0.0.1",
|
||||
|
@ -69,6 +70,7 @@ dependencies = [
|
|||
"sleep 0.0.1",
|
||||
"sort 0.0.1",
|
||||
"split 0.0.1",
|
||||
"stat 0.0.1",
|
||||
"stdbuf 0.0.1",
|
||||
"sum 0.0.1",
|
||||
"sync 0.0.1",
|
||||
|
@ -115,6 +117,15 @@ dependencies = [
|
|||
"memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arch"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uucore 0.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.0.1"
|
||||
|
@ -553,6 +564,11 @@ dependencies = [
|
|||
"uucore 0.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "1.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "nproc"
|
||||
version = "0.0.1"
|
||||
|
@ -852,6 +868,14 @@ name = "semver"
|
|||
version = "0.1.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"nom 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "seq"
|
||||
version = "0.0.1"
|
||||
|
@ -898,6 +922,7 @@ version = "0.0.1"
|
|||
dependencies = [
|
||||
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uucore 0.0.1",
|
||||
]
|
||||
|
||||
|
@ -910,6 +935,16 @@ dependencies = [
|
|||
"uucore 0.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stat"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uucore 0.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stdbuf"
|
||||
version = "0.0.1"
|
||||
|
|
|
@ -6,6 +6,7 @@ build = "build.rs"
|
|||
|
||||
[features]
|
||||
unix = [
|
||||
"arch",
|
||||
"chmod",
|
||||
"chroot",
|
||||
"du",
|
||||
|
@ -96,6 +97,7 @@ test_unimplemented = []
|
|||
|
||||
[dependencies]
|
||||
uucore = { path="src/uucore" }
|
||||
arch = { optional=true, path="src/arch" }
|
||||
base64 = { optional=true, path="src/base64" }
|
||||
basename = { optional=true, path="src/basename" }
|
||||
cat = { optional=true, path="src/cat" }
|
||||
|
|
1
Makefile
1
Makefile
|
@ -98,6 +98,7 @@ PROGS := \
|
|||
yes
|
||||
|
||||
UNIX_PROGS := \
|
||||
arch \
|
||||
chmod \
|
||||
chroot \
|
||||
du \
|
||||
|
|
17
src/arch/Cargo.toml
Normal file
17
src/arch/Cargo.toml
Normal file
|
@ -0,0 +1,17 @@
|
|||
[package]
|
||||
name = "arch"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
|
||||
[lib]
|
||||
name = "uu_arch"
|
||||
path = "arch.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "*"
|
||||
libc = "*"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[[bin]]
|
||||
name = "arch"
|
||||
path = "main.rs"
|
76
src/arch/arch.rs
Normal file
76
src/arch/arch.rs
Normal file
|
@ -0,0 +1,76 @@
|
|||
#![crate_name = "uu_arch"]
|
||||
|
||||
/*
|
||||
* This file is part of the uutils coreutils package.
|
||||
*
|
||||
* (c) Smigle00 <smigle00@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
extern crate getopts;
|
||||
extern crate libc;
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::io::Write;
|
||||
use std::mem::uninitialized;
|
||||
use uucore::c_types::utsname;
|
||||
|
||||
struct Arch {
|
||||
arch_name: String
|
||||
}
|
||||
|
||||
extern {
|
||||
fn uname(uts: *mut utsname);
|
||||
}
|
||||
|
||||
unsafe fn string_from_c_str(ptr: *const i8) -> String {
|
||||
String::from_utf8_lossy(CStr::from_ptr(ptr as *const std::os::raw::c_char).to_bytes()).to_string()
|
||||
}
|
||||
|
||||
unsafe fn get_machine_arch() -> Arch {
|
||||
let mut uts: utsname = uninitialized();
|
||||
uname(&mut uts);
|
||||
Arch {
|
||||
arch_name: string_from_c_str(uts.machine.as_ptr() as *const i8)
|
||||
}
|
||||
}
|
||||
|
||||
static NAME: &'static str = "arch";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let mut opts = getopts::Options::new();
|
||||
|
||||
opts.optflag("", "help", "display this help and exit");
|
||||
opts.optflag("", "version", "output version information and exit");
|
||||
|
||||
let matches = match opts.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(f) => crash!(1, "{}\nTry '{} --help' for more information.", f, NAME),
|
||||
};
|
||||
|
||||
if matches.opt_present("help") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
println!("");
|
||||
println!("Usage:");
|
||||
println!(" {} [OPTIONS]...", NAME);
|
||||
println!("");
|
||||
print!("{}", opts.usage("Print machine architecture name."));
|
||||
return 0;
|
||||
} else if matches.opt_present("version") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
let machine_arch = unsafe { get_machine_arch() };
|
||||
let mut output = String::new();
|
||||
output.push_str(machine_arch.arch_name.as_ref());
|
||||
println!("{}", output.trim());
|
||||
|
||||
0
|
||||
}
|
5
src/arch/main.rs
Normal file
5
src/arch/main.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
extern crate uu_arch;
|
||||
|
||||
fn main() {
|
||||
std::process::exit(uu_arch::uumain(std::env::args().collect()));
|
||||
}
|
Loading…
Reference in a new issue