Use sched_getaffinity to get the number of cores on linux

This gets rid of the code that parses /proc/cpuinfo, and avoids
forking within the library.

The previous code also failed build on modern glibc versions
due to ignoring the return value of the system, read and write
system calls.
Use sysctl instead of the deprecated Gestalt API for getting the number of cores on OS X

Also use the __APPLE__ predefined define instead of MACOS for enabling
these code paths.

This also avoids having to link to the CoreServices framework in
order to get the Gestalt function.
Merge pull request #181 from mstorsjo/threadlib-update-macos-linux

Update the cpu core count detection functions for linux and mac os