Check ferror(stdout) and exit(1) if there's been a problem.Fixes PR bin/39574 from Ed Ravin, but with a simpler patch.