mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-04 06:57:47 +00:00
nproc: fix windows
This commit is contained in:
parent
3a4b5ff8ed
commit
adb39d411b
1 changed files with 13 additions and 6 deletions
|
@ -11,6 +11,8 @@
|
|||
|
||||
extern crate getopts;
|
||||
extern crate num_cpus;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
extern crate libc;
|
||||
|
||||
#[macro_use]
|
||||
|
@ -83,6 +85,7 @@ Print the number of cores available to the current process.", NAME, VERSION);
|
|||
}
|
||||
|
||||
let mut cores = if matches.opt_present("all") {
|
||||
if cfg!(unix) {
|
||||
let nprocs = unsafe { libc::sysconf(_SC_NPROCESSORS_CONF) };
|
||||
if nprocs == 1 {
|
||||
// In some situation, /proc and /sys are not mounted, and sysconf returns 1.
|
||||
|
@ -93,6 +96,10 @@ Print the number of cores available to the current process.", NAME, VERSION);
|
|||
}
|
||||
} else {
|
||||
num_cpus::get()
|
||||
}
|
||||
} else {
|
||||
// On windows, num_cpus::get() directly.
|
||||
num_cpus::get()
|
||||
};
|
||||
|
||||
if cores <= ignore {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue