Subject: [clisp-list] testing for eof

From: [email-masked] (Don Cohen)
Date: Mon, 12 Jun 2000 05:42:57 -0400

I sent an earlier message about socket streams but I now think
that this is a more general problem, a hole in the cl spec.
The problem:
 how can I tell when I've reached the end of a stream?
Well, there is a way for character streams:
 (defun eof-p (stream)
   (let ((ans (read-char-no-hang stream nil :eof)))
     ;; ans is now a char, nil or :eof
     (when (eql ans :eof) (return-from eof-p t))
     (when ans (unread-char ans stream))
     nil))

If it's a binary stream what can I do?
There's no unread-byte.  There's no read-byte-no-hang.
The closest I can see is changing the stream to a character stream
then doing above, then changing it back.  This does not work, though.
If the read-char-no-hang returns #\newline there's no reason to expect
that the unread-char will restore the stream to its previous state
with respect to read-byte.  The input might have contained crlf and
be restored to only lf or vice versa.

So, here's my next request.  Could we have an eof-p function that
works on binary streams (preferably on all streams)?
Unlike some of my other recent requests, this seems like one that 
should be easy to implement.