mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 05:57:46 +00:00
commit
cf1723892d
3 changed files with 12 additions and 8 deletions
1
deps/Cargo.toml
vendored
1
deps/Cargo.toml
vendored
|
@ -7,6 +7,7 @@ name = "null"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.1.6"
|
libc = "0.1.6"
|
||||||
|
num_cpus = "*"
|
||||||
rand = "0.3.8"
|
rand = "0.3.8"
|
||||||
regex = "0.1.30"
|
regex = "0.1.30"
|
||||||
regex_macros = "0.1.17"
|
regex_macros = "0.1.17"
|
||||||
|
|
1
src/nproc/deps.mk
Normal file
1
src/nproc/deps.mk
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DEPLIBS += num_cpus
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "nproc"]
|
#![crate_name = "nproc"]
|
||||||
#![feature(collections, os, rustc_private)]
|
#![feature(rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -11,8 +11,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
extern crate num_cpus;
|
||||||
|
|
||||||
use std::os;
|
use std::env;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
static NAME : &'static str = "nproc";
|
static NAME : &'static str = "nproc";
|
||||||
static VERSION : &'static str = "0.0.0";
|
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"),
|
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,
|
Ok(m) => m,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
show_error!("{}", err);
|
show_error!("{}", err);
|
||||||
|
@ -46,7 +48,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
println!("{} {}", NAME, VERSION);
|
println!("{} {}", NAME, VERSION);
|
||||||
println!("");
|
println!("");
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {} [OPTIONS] NAME...", NAME);
|
println!(" {} [OPTIONS]...", NAME);
|
||||||
println!("");
|
println!("");
|
||||||
print!("{}", getopts::usage("Print the number of cores available to the current process.", &opts));
|
print!("{}", getopts::usage("Print the number of cores available to the current process.", &opts));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -64,16 +66,16 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
};
|
};
|
||||||
|
|
||||||
if !matches.opt_present("all") {
|
if !matches.opt_present("all") {
|
||||||
ignore += match os::getenv("OMP_NUM_THREADS") {
|
ignore += match env::var("OMP_NUM_THREADS") {
|
||||||
Some(threadstr) => match threadstr.parse() {
|
Ok(threadstr) => match threadstr.parse() {
|
||||||
Ok(num) => num,
|
Ok(num) => num,
|
||||||
Err(_)=> 0
|
Err(_)=> 0
|
||||||
},
|
},
|
||||||
None => 0
|
Err(_) => 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cores = os::num_cpus();
|
let mut cores = num_cpus::get();
|
||||||
if cores <= ignore {
|
if cores <= ignore {
|
||||||
cores = 1;
|
cores = 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue