rktio: fix bug in 'text mode on Windows

If a #\return lined up in just the wrong way with a file-read
request, then the #\return could get mishandled.
This commit is contained in:
Matthew Flatt 2017-10-19 19:55:38 -06:00
parent b6b9d0d409
commit e255c737b5
3 changed files with 19 additions and 0 deletions

View File

@ -371,6 +371,23 @@
(delete-directory/files dir))
;; ----------------------------------------
;; Check 'text mode conversion
;; The content of "text.rktd" once triggered a bug in 'text
;; mode conversion on Windows by having line breaks as just
;; the right place
(let ()
(define text (call-with-input-file (build-path (current-load-relative-directory)
"text.rktd")
read))
(define tmp (make-temporary-file "tmp-data~a"))
(call-with-output-file tmp #:exists 'truncate (lambda (o) (write-string text o)))
(define str (file->string tmp #:mode 'text))
(test #t values (equal? str (if (eq? (system-type) 'windows)
(regexp-replace* #rx"\r\n" text "\n")
text))))
;; ----------------------------------------
(report-errs)

File diff suppressed because one or more lines are too long

View File

@ -797,6 +797,7 @@ intptr_t rktio_read_converted(rktio_t *rktio, rktio_fd_t *rfd, char *buffer, int
}
} else {
/* read after first byte installed into the buffer */
rfd->has_pending_byte = 0;
offset = 1;
}
}