Fix ks_getuntil2() extra empty record at EOF bug

When the stream is an exact multiple of the buffer size, `ks_getuntil2()` was returning a final empty record when it should have returned -1.  Fixed by moving the "EOF => return -1" check to after the read loop.

(See samtools/samtools#318 for an example of an error caused by a spurious empty line at the end of a SAM file.)

Also put the repeated `if (ks->end == 0) something;` lines from 8d8d1a19f0c69b53d5ed8d9f6592dfa4b91c23f3 into a single `if` each.