Also fail if fwrite() returns 0, not only if it returns false.

Closes #34.