Support Mac OS X

Bug 1012833 - Negatus should build on Mac OS X.

Bug 1012833 - Further review comments integrated.
Bug 1012855 - Files are being written with corrupt data.

Bug 1012855 - Further review feedback.