mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-15 03:26:18 +00:00
nproc: fix compilation on windows
This commit is contained in:
parent
adb39d411b
commit
57dd3703d0
1 changed files with 7 additions and 3 deletions
|
@ -22,9 +22,13 @@ use std::io::Write;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub const _SC_NPROCESSORS_CONF: libc::c_int = 83; // libc crate hasn't!!
|
pub const _SC_NPROCESSORS_CONF: libc::c_int = 83;
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(target_os = "macos")]
|
||||||
pub const _SC_NPROCESSORS_CONF: libc::c_int = libc::_SC_NPROCESSORS_CONF;
|
pub const _SC_NPROCESSORS_CONF: libc::c_int = libc::_SC_NPROCESSORS_CONF;
|
||||||
|
#[cfg(target_os = "freebsd")]
|
||||||
|
pub const _SC_NPROCESSORS_CONF: libc::c_int = 57;
|
||||||
|
#[cfg(target_os = "netbsd")]
|
||||||
|
pub const _SC_NPROCESSORS_CONF: libc::c_int = 1001;
|
||||||
|
|
||||||
|
|
||||||
static NAME: &'static str = "nproc";
|
static NAME: &'static str = "nproc";
|
||||||
|
@ -85,7 +89,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) {
|
if cfg!(target_os = "linux") || cfg!(target_os = "macos") || cfg!(target_os = "freebsd") || cfg!(target_os = "netbsd") {
|
||||||
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.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue