[PATCH] D20409: [LibFuzzer] Fix NumberOfCpuCores() for Mac OSX

Dan Liew via llvm-commits llvm-commits at lists.llvm.org
Wed May 18 20:35:46 PDT 2016


delcypher created this revision.
delcypher added reviewers: kcc, aizatsky, kubabrecka.
delcypher added subscribers: llvm-commits, kcc, aizatsky, kubabrecka.

[LibFuzzer]
Fix the detection of the number of CPUs on Mac OSX. The ``nprocs`` command does not exist on that platform.

http://reviews.llvm.org/D20409

Files:
  lib/Fuzzer/FuzzerUtil.cpp

Index: lib/Fuzzer/FuzzerUtil.cpp
===================================================================
--- lib/Fuzzer/FuzzerUtil.cpp
+++ lib/Fuzzer/FuzzerUtil.cpp
@@ -113,7 +113,13 @@
 void SetSigTermHandler() { SetSigaction(SIGTERM, InterruptHandler); }
 
 int NumberOfCpuCores() {
+#ifdef __linux__
   FILE *F = popen("nproc", "r");
+#elif __APPLE__
+  FILE *F = popen("sysctl -n hw.ncpu", "r");
+#else
+#error "NumberOfCpuCores() is not implemented for your platform"
+#endif
   int N = 0;
   if (fscanf(F, "%d", &N) != 1)
     N = 1;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20409.57730.patch
Type: text/x-patch
Size: 536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160519/da029689/attachment.bin>


More information about the llvm-commits mailing list