From 57dd3703d053bfff8609a59ede37077f534cafb6 Mon Sep 17 00:00:00 2001 From: Hiroki Noda Date: Mon, 29 May 2017 09:54:56 +0900 Subject: [PATCH] nproc: fix compilation on windows --- src/nproc/nproc.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/nproc/nproc.rs b/src/nproc/nproc.rs index 3cfe5a0ca..d7a5509ae 100644 --- a/src/nproc/nproc.rs +++ b/src/nproc/nproc.rs @@ -22,9 +22,13 @@ use std::io::Write; use std::env; #[cfg(target_os = "linux")] -pub const _SC_NPROCESSORS_CONF: libc::c_int = 83; // libc crate hasn't!! -#[cfg(not(target_os = "linux"))] +pub const _SC_NPROCESSORS_CONF: libc::c_int = 83; +#[cfg(target_os = "macos")] 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"; @@ -85,7 +89,7 @@ Print the number of cores available to the current process.", NAME, VERSION); } 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) }; if nprocs == 1 { // In some situation, /proc and /sys are not mounted, and sysconf returns 1.