1
Fork 0
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:
Hiroki Noda 2017-05-29 09:41:29 +09:00
parent 3a4b5ff8ed
commit adb39d411b

View file

@ -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,6 +85,7 @@ 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") {
if cfg!(unix) {
let nprocs = unsafe { libc::sysconf(_SC_NPROCESSORS_CONF) }; let nprocs = unsafe { libc::sysconf(_SC_NPROCESSORS_CONF) };
if nprocs == 1 { if nprocs == 1 {
// In some situation, /proc and /sys are not mounted, and sysconf returns 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 { } else {
num_cpus::get() num_cpus::get()
}
} else {
// On windows, num_cpus::get() directly.
num_cpus::get()
}; };
if cores <= ignore { if cores <= ignore {