Browse files

fix build on non-Linux glibc systems

ninja-build does not build on non-Linux archs, such as
GNU/kFreeBSD and GNU/Hurd.

The problem is that the GetProcessorCount() implementation for these
architectures is the sysconf() one, but <unistd.h> has not been
included, causing sysconf() and _SC_NPROCESSORS_ONLN to not be
declared. Another solution (which is the one I chose) is to make use
of the "linux" implementation which uses get_nprocs(), which is a GNU
extension and thus available for anything using GNU libc.
  • Loading branch information...
Pino Toscano authored and evmar committed Dec 29, 2012
1 parent 34b46f2 commit e38eb5438151b5accc43e7e5d91f1435a2450f2f
Showing with 2 additions and 2 deletions.
  1. +2 −2 src/
@@ -39,7 +39,7 @@
#elif defined(__SVR4) && defined(__sun)
#include <unistd.h>
#include <sys/loadavg.h>
-#elif defined(linux)
+#elif defined(linux) || defined(__GLIBC__)
#include <sys/sysinfo.h>
@@ -295,7 +295,7 @@ string StripAnsiEscapeCodes(const string& in) {
return stripped;
-#if defined(linux)
+#if defined(linux) || defined(__GLIBC__)
int GetProcessorCount() {
return get_nprocs();

0 comments on commit e38eb54

Please sign in to comment.