From: Eric Petit Date: Wed, 2 Aug 2006 18:11:21 +0000 (+0000) Subject: Nicer OS X x264_cpu_num_processors (thanks David) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1ff80a23db8912967238d1d9d4df2aebeeafbd1a;p=libx264 Nicer OS X x264_cpu_num_processors (thanks David) git-svn-id: svn://svn.videolan.org/x264/trunk@547 df754926-b1dd-0310-bc7b-ec298dee348c --- diff --git a/common/cpu.c b/common/cpu.c index 7389d03c..3e50d45c 100644 --- a/common/cpu.c +++ b/common/cpu.c @@ -28,8 +28,11 @@ #ifdef SYS_BEOS #include #endif +#ifdef SYS_MACOSX +#include +#include +#endif -#include #include #include "common.h" @@ -178,22 +181,13 @@ int x264_cpu_num_processors( void ) return info.cpu_count; #elif defined(SYS_MACOSX) - FILE * pipe; - char buffer[16]; - int num = 1; - if( ( pipe = popen( "/usr/sbin/sysctl hw.ncpu", "r" ) ) ) - { - memset( buffer, 0, 16 ); - if( fgets( buffer, 16, pipe ) ) - { - if( sscanf( buffer, "hw.ncpu: %d", &num ) != 1 ) - { - num = 1; - } - } - fclose( pipe ); + int numberOfCPUs; + size_t length = sizeof( numberOfCPUs ); + if( sysctlbyname("hw.ncpu", &numberOfCPUs, &length, NULL, 0) ) + { + numberOfCPUs = 1; } - return num; + return numberOfCPUs; #else return 1;