From 3149c002644b927e0245d237cdda3a6aeca00e4a Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Sun, 16 Jun 2019 16:18:29 +0200 Subject: utils: canonical-newline-port: Fix handling of carriage return at buffer end. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prior to this change the added test fails for me locally at byte 1024. It might depend on some default buffer sizes. Fixes . * tests/utils.scm ("canonical-newline-port-1024"): Add test. * guix/utils.scm (canonical-newline-port): Correct comments on CR/LF. Remove CR even when they're at the end of the buffer. Signed-off-by: Ludovic Courtès --- guix/utils.scm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'guix') diff --git a/guix/utils.scm b/guix/utils.scm index 709cdf9353..f480c3291f 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -718,7 +718,7 @@ (define (absolute target) (define (canonical-newline-port port) "Return an input port that wraps PORT such that all newlines consist - of a single carriage return." + of a single linefeed." (define (get-position) (if (port-has-port-position? port) (port-position port) #f)) (define (set-position! position) @@ -730,11 +730,11 @@ (define (read! bv start n) (let loop ((count 0) (byte (get-u8 port))) (cond ((eof-object? byte) count) + ;; XXX: consume all CRs even if not followed by LF. + ((eqv? byte (char->integer #\return)) (loop count (get-u8 port))) ((= count (- n 1)) (bytevector-u8-set! bv (+ start count) byte) n) - ;; XXX: consume all LFs even if not followed by CR. - ((eqv? byte (char->integer #\return)) (loop count (get-u8 port))) (else (bytevector-u8-set! bv (+ start count) byte) (loop (+ count 1) (get-u8 port)))))) -- cgit v1.2.3