From 4da607e09383e71134c5ba1622f3c31803f8ea9b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 12 Aug 2015 06:32:11 -0700 Subject: Catenated stream reads must not close last stream. * stream.c (cat_get_line, cat_get_char, cat_get_byte) Only close the head stream when popping it off the list. --- stream.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'stream.c') diff --git a/stream.c b/stream.c index 20cf1e14..5a74bdc6 100644 --- a/stream.c +++ b/stream.c @@ -1720,9 +1720,10 @@ static val cat_get_line(val stream) val line = get_line(fs); if (line) return line; - close_stream(fs, t); - if ((streams = rest(streams)) != nil) + if ((streams = rest(streams)) != nil) { + close_stream(fs, t); set(mkloc(s->streams, stream), streams); + } } return nil; @@ -1738,9 +1739,10 @@ static val cat_get_char(val stream) val ch = get_char(fs); if (ch) return ch; - close_stream(fs, t); - if ((streams = rest(streams)) != nil) + if ((streams = rest(streams)) != nil) { + close_stream(fs, t); set(mkloc(s->streams, stream), streams); + } } return nil; @@ -1756,9 +1758,10 @@ static val cat_get_byte(val stream) val byte = get_byte(fs); if (byte) return byte; - close_stream(fs, t); - if ((streams = rest(streams)) != nil) + if ((streams = rest(streams)) != nil) { + close_stream(fs, t); set(mkloc(s->streams, stream), streams); + } } return nil; -- cgit v1.2.3