[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: drain-input

From: Gary Houston
Subject: Re: drain-input
Date: 4 Sep 2001 22:02:23 -0000

> From: Alex Shinn <address@hidden>
> Date: 30 Aug 2001 02:19:30 -0400
> For the particular problem of getting the contents of a file as a
> string, I ended up doing
> (define (file-contents file)
>   (call-with-input-file file
>     (lambda (p)
>       (let* ((size (stat:size (stat p)))
>              (buf (make-string size)))
>         (read-string!/partial buf p)
>         buf))))

Take a bit of care with read-string!/partial: it's not guaranteed to
return all the characters that you ask for, even when EOF is not
reached.  There should be loop around it, or read-string!  should be
used instead (which is not available in (ice-9 rw) at present,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]