Check write(2) return values and gracefully handle failures.  (closes #9)