From ce8d5c66abfd3ef153e47381405ab88d97e60134 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 25 Apr 2019 08:29:15 +0200 Subject: [PATCH] fix https://github.com/RfidResearchGroup/proxmark3/issues/173 this seems to work for OSX, and improved linux version with fallback. --- client/util.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/client/util.c b/client/util.c index b14023067..3c7ef4ba0 100644 --- a/client/util.c +++ b/client/util.c @@ -866,9 +866,18 @@ int num_CPUs(void) { SYSTEM_INFO sysinfo; GetSystemInfo(&sysinfo); return sysinfo.dwNumberOfProcessors; -#elif defined(__linux__) || defined(__APPLE__) +#elif defined(__linux__) && defined(_SC_NPROCESSORS_ONLN) #include - return sysconf(_SC_NPROCESSORS_ONLN); + int count = sysconf(_SC_NPROCESSORS_ONLN); + if (count <= 0) + count = 1; + return count; +#elif defined(__APPLE__) +#include "sys/sysctl.h" + uint32 logicalcores = 0; + size_t size = sizeof( logicalcores ); + sysctlbyname( "hw.logicalcpu", &logicalcores, &size, NULL, 0 ); + return logicalcores; #else return 1; #endif