Fix builds on Mac OS X.

Thanks to @kode54 for his bug reports and assistance.