Fix build on OS X

* There is no direct equivalent of O_DIRECT, just warn.
* error(3) is glibc-specific.
* There were a couple missing includes.