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 getopts;
|
||||||
extern crate num_cpus;
|
extern crate num_cpus;
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -83,15 +85,20 @@ Print the number of cores available to the current process.", NAME, VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cores = if matches.opt_present("all") {
|
let mut cores = if matches.opt_present("all") {
|
||||||
let nprocs = unsafe { libc::sysconf(_SC_NPROCESSORS_CONF) };
|
if cfg!(unix) {
|
||||||
if nprocs == 1 {
|
let nprocs = unsafe { libc::sysconf(_SC_NPROCESSORS_CONF) };
|
||||||
// In some situation, /proc and /sys are not mounted, and sysconf returns 1.
|
if nprocs == 1 {
|
||||||
// However, we want to guarantee that `nproc --all` >= `nproc`.
|
// In some situation, /proc and /sys are not mounted, and sysconf returns 1.
|
||||||
num_cpus::get()
|
// However, we want to guarantee that `nproc --all` >= `nproc`.
|
||||||
|
num_cpus::get()
|
||||||
|
} else {
|
||||||
|
if nprocs > 0 { nprocs as usize } else { 1 }
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if nprocs > 0 { nprocs as usize } else { 1 }
|
num_cpus::get()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// On windows, num_cpus::get() directly.
|
||||||
num_cpus::get()
|
num_cpus::get()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue