[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: drain-input
From: |
Thien-Thi Nguyen |
Subject: |
Re: drain-input |
Date: |
Thu, 06 Sep 2001 15:55:45 -0700 |
From: Gary Houston <address@hidden>
Date: 4 Sep 2001 22:02:23 -0000
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,
regretfully).
fyi, below is a proc extracted from module `(ttn fileutils)' that uses
`read-string!/partial' in a loop (the extra hair is for interoperability
w/ module `(ttn gap-buffer)').
thi
__________________________________________
;; Insert file named FILENAME into a buffer, and return that buffer.
;; FILENAME is passed through `expand-file-name', q.v.
;; If the file is not readable, return #f.
;; This causes the buffer to visit the file.
;;
(define (find-file filename)
(let ((filename (expand-file-name filename)))
(and (access? filename R_OK)
(let* ((sz (stat:size (stat filename)))
(str (make-string sz))
(fp (open-file filename "r")))
(do ((so-far 0 (+ so-far (read-string!/partial str fp so-far))))
((= so-far sz)))
(let ((buf (make-gap-buffer)))
(gb-insert-string! buf str)
(set-object-property! buf 'filename filename)
(gb-goto-char buf (gb-point-min buf))
buf)))))