Introduce UnexpectedError to handle non-fatal failures.

The error message is printed to stderr, and the function does not exit.
Handle return values from various C functions.

This silences numerous compiler warnings on Ubuntu 12.04, and handles
error cases that were previously ignored, with possibly undefined outcome.