From 5538372dc5eee71d882d6cf3c8073e89faab55ba Mon Sep 17 00:00:00 2001 From: Moshe Gottlieb Date: Sun, 8 Jan 2017 11:04:33 +0200 Subject: [PATCH] Use sysconf on macOS to determine number of CPUs Added #if defined(__APPLE__) wrapper for count_processors, using sysconf (libc, include unistd.h which is already indirectly included). sysconf(_SC_NPROCESSORS_ONLN) returns the number of processors currently online or -1 if there was an error, this function uses -1 to denote an error so this works fine. --- vanitygen.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vanitygen.c b/vanitygen.c index 9d88121..be4bfd5 100644 --- a/vanitygen.c +++ b/vanitygen.c @@ -244,6 +244,9 @@ vg_thread_loop(void *arg) int count_processors(void) { +#if defined(__APPLE__) + int count = sysconf(_SC_NPROCESSORS_ONLN); +#else FILE *fp; char buf[512]; int count = 0; @@ -257,7 +260,8 @@ count_processors(void) count += 1; } fclose(fp); - return count; +#endif + return count; } #endif