From c170f390a71719e7d2a8b1b6aa60506639a96484 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 21 Aug 2008 19:43:45 +0000 Subject: [PATCH] fix r6rs custom ports for flushing svn: r11370 --- collects/rnrs/io/ports-6.ss | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/collects/rnrs/io/ports-6.ss b/collects/rnrs/io/ports-6.ss index 32e38c13fc..ff2a0faf07 100644 --- a/collects/rnrs/io/ports-6.ss +++ b/collects/rnrs/io/ports-6.ss @@ -833,7 +833,9 @@ id always-evt ;; assuming that it never blocks! (lambda (bytes start end can-block/buffer? enable-break?) - (write! bytes start end)) + (if (= start end) + 0 + (write! bytes start end))) (or close void) #f #f @@ -862,8 +864,10 @@ (bytes-utf-8-length bytes #f start end)) ;; No old bytes saved, and bytes to write form a complete ;; UTF-8 encoding, so we can write directly: - (let ([s (bytes->string/utf-8 bytes #f start end)]) - (write! s 0 (string-length s))) + (let* ([s (bytes->string/utf-8 bytes #f start end)] + [len (string-length s)]) + (when (positive? len) + (write! s 0 len))) ;; Partial or need to use existing bytes, so use pipe (begin (write-bytes bytes out start end) @@ -877,8 +881,10 @@ (let-values ([(amt used status) (bytes-convert c buffer 0 n cvt-buffer)]) (when (positive? amt) (read-bytes! buffer in 0 amt) - (let ([s (bytes->string/utf-8 buffer #f 0 amt)]) - (write! s 0 (string-length s)))) + (let* ([s (bytes->string/utf-8 buffer #f 0 amt)] + [len (string-length s)]) + (when (positive? len) + (write! s 0 (string-length s))))) (when (eq? status 'error) ;; Discard an erroneous byte (read-byte in))