Historically, lam(1) closes stdin once we've hit EOF the first time,
which would stop it from doing anything else on subsequent gatherline()
calls with another openfile. However, this doesn't seem to be strictly
necessary- the EOF flag on FILEs is quite sticky, so we can assume that
a subsequent fgetc(stdin) will flag EOF properly.
This 'fixes' the below-referenced commit in the sense that it surfaced
this problem as a fatal error, but the issue was pre-existing. If we
do lam - -, then one gatherline() will fclose(stdin) and set ip->eof
for *that* openfile, while the next one will then observe that
STDIN_FILENO has been closed and turn it into an EBADF.
Add a few tests that were easy to snipe while I'm here, but I haven't
aimed for anything close to exhaustive because think re@ would prefer
this fix go in sooner rather than later to land in 15.0.
Reported by: cperciva
Fixes: 4472fd66d006 ("lam: fail on I/O errors")
Sponsored by: Klara, Inc.