Bugfix: stdio-like EOF flags

Now we set eof flag only if we read EOF, not when we reach it.