src/streams.lisp @ 443af0e76dd6 default tip

Add with-eof-handled
author Steve Losh <steve@stevelosh.com>
date Sun, 23 Jun 2024 13:34:51 -0400
parents (none)
children (none)
(in-package :losh.streams)

(defmacro with-eof-handled ((stream eof-error-p eof-value) &body body)
  (alexandria:once-only (stream eof-error-p eof-value)
    `(if (null (peek-char nil ,stream nil))
       (if ,eof-error-p
         (error 'end-of-file)
         ,eof-value)
       (progn ,@body))))