hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 62b3ef51f7f40bbb5e838801efceb10e75d6291a
parent e83f3f40b015d725a43f36e1ea0ec4a85f4ab975
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed,  4 Jan 2023 14:35:11 +0100

io::limit*: fix behavior on underread/underwrite

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mio/limit.ha | 14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/io/limit.ha b/io/limit.ha @@ -51,8 +51,13 @@ fn limit_read(s: *stream, buf: []u8) (size | EOF | error) = { if (len(buf) > stream.limit) { buf = buf[..stream.limit]; }; - stream.limit -= len(buf); - return read(stream.source, buf); + match (read(stream.source, buf)) { + case EOF => + return EOF; + case let z: size => + stream.limit -= z; + return z; + }; }; fn limit_write(s: *stream, buf: const []u8) (size | error) = { @@ -65,6 +70,7 @@ fn limit_write(s: *stream, buf: const []u8) (size | error) = { } else { yield buf[..]; }; - stream.limit -= len(slice); - return write(stream.source, slice); + const z = write(stream.source, slice)?; + stream.limit -= z; + return z; };