Only continue flushing stdin if data has actually been read.

Code as was would repeatedly call read() until it returned -1. However,
read() returns 0 at EOF (and I've seen this function spin because of this),
and I've read that ‘some other implementations’ may return -2.