1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 13:37:48 +00:00

Merge pull request #590 from jbcrail/fix-nproc

Fix nproc.
This commit is contained in:
Heather 2015-05-11 08:08:21 +03:00
commit cf1723892d
3 changed files with 12 additions and 8 deletions

1
deps/Cargo.toml vendored
View file

@ -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"

1
src/nproc/deps.mk Normal file
View file

@ -0,0 +1 @@
DEPLIBS += num_cpus

View file

@ -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<String>) -> 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<String>) -> 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<String>) -> 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 {