check the return value of `fwrite`