Implement strndup explicitly if __APPLE__ is defined

Intended to fix issue #9. The implementation of strndup was obtained from
http://www.opensource.apple.com/source/gcc/gcc-5666.3/libiberty/strndup.c
under the GPL license.

For reference, see also http://stackoverflow.com/questions/6062822/whats-wrong-with-strndup