diff --git a/deps/Cargo.toml b/deps/Cargo.toml index 622eef41d..0915db569 100644 --- a/deps/Cargo.toml +++ b/deps/Cargo.toml @@ -7,6 +7,7 @@ name = "null" [dependencies] libc = "0.1.6" +num_cpus = "*" rand = "0.3.8" regex = "0.1.30" regex_macros = "0.1.17" diff --git a/src/nproc/deps.mk b/src/nproc/deps.mk new file mode 100644 index 000000000..8bd1a6c62 --- /dev/null +++ b/src/nproc/deps.mk @@ -0,0 +1 @@ +DEPLIBS += num_cpus diff --git a/src/nproc/nproc.rs b/src/nproc/nproc.rs index 2d5cd57ac..dc3ad1935 100644 --- a/src/nproc/nproc.rs +++ b/src/nproc/nproc.rs @@ -1,5 +1,5 @@ #![crate_name = "nproc"] -#![feature(collections, os, rustc_private)] +#![feature(rustc_private)] /* * This file is part of the uutils coreutils package. @@ -11,8 +11,10 @@ */ extern crate getopts; +extern crate num_cpus; -use std::os; +use std::env; +use std::io::Write; static NAME : &'static str = "nproc"; static VERSION : &'static str = "0.0.0"; @@ -29,7 +31,7 @@ pub fn uumain(args: Vec) -> i32 { getopts::optflag("V", "version", "output version information and exit"), ]; - let matches = match getopts::getopts(args.tail(), &opts) { + let matches = match getopts::getopts(&args[1..], &opts) { Ok(m) => m, Err(err) => { show_error!("{}", err); @@ -46,7 +48,7 @@ pub fn uumain(args: Vec) -> i32 { println!("{} {}", NAME, VERSION); println!(""); println!("Usage:"); - println!(" {} [OPTIONS] NAME...", NAME); + println!(" {} [OPTIONS]...", NAME); println!(""); print!("{}", getopts::usage("Print the number of cores available to the current process.", &opts)); return 0; @@ -64,16 +66,16 @@ pub fn uumain(args: Vec) -> i32 { }; if !matches.opt_present("all") { - ignore += match os::getenv("OMP_NUM_THREADS") { - Some(threadstr) => match threadstr.parse() { + ignore += match env::var("OMP_NUM_THREADS") { + Ok(threadstr) => match threadstr.parse() { Ok(num) => num, Err(_)=> 0 }, - None => 0 + Err(_) => 0 }; } - let mut cores = os::num_cpus(); + let mut cores = num_cpus::get(); if cores <= ignore { cores = 1; } else {