Improve how posix errors are handled; extend and fix unit tests.