mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 14:49:18 +02:00
Fixing read-bytevector to use read-u8 instead of the hacked definition in terms of read-string.
This commit is contained in:
parent
60c96d76a4
commit
b5046925f7
1 changed files with 12 additions and 5 deletions
|
@ -43,11 +43,18 @@
|
||||||
|
|
||||||
(define (read-bytevector n . o)
|
(define (read-bytevector n . o)
|
||||||
(if (zero? n)
|
(if (zero? n)
|
||||||
""
|
#u8()
|
||||||
(let ((res (read-string n (if (pair? o) (car o) (current-input-port)))))
|
(let ((in (if (pair? o) (car o) (current-input-port)))
|
||||||
(if (eof-object? res)
|
(res (make-bytevector n)))
|
||||||
res
|
(let lp ((i 0))
|
||||||
(string->utf8 res)))))
|
(if (>= i n)
|
||||||
|
res
|
||||||
|
(let ((x (read-u8 in)))
|
||||||
|
(cond ((eof-object? x)
|
||||||
|
(if (zero? i) x (subbytes res 0 i)))
|
||||||
|
(else
|
||||||
|
(bytevector-u8-set! res i x)
|
||||||
|
(lp (+ i 1))))))))))
|
||||||
|
|
||||||
(define (read-bytevector! vec start end . o)
|
(define (read-bytevector! vec start end . o)
|
||||||
(if (>= start end)
|
(if (>= start end)
|
||||||
|
|
Loading…
Add table
Reference in a new issue