hare

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

commit b243b12ad65031bbbf32ff0d6af81b1846ffd117
parent 9b0f8a80ffc360b1b547270bd12668125be459b5
Author: Bor Grošelj Simić <bgs@turminal.net>
Date:   Sat, 23 Apr 2022 15:08:57 +0200

store amount of succesfully read data in io::underread

Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>

Diffstat:
Mcrypto/blake2b/blake2b.ha | 2+-
Mio/limit.ha | 2+-
Mio/types.ha | 5+++--
Mio/util.ha | 4++--
4 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/crypto/blake2b/blake2b.ha b/crypto/blake2b/blake2b.ha @@ -84,7 +84,7 @@ export fn blake2b(key: []u8, sz: size) digest = { }; fn write(st: *io::stream, buf: const []u8) (size | io::error) = { - if (len(buf) == 0) return 0; + if (len(buf) == 0) return 0z; let h = st: *digest; let length = len(buf); let buf = buf[..]; diff --git a/io/limit.ha b/io/limit.ha @@ -58,7 +58,7 @@ fn limit_read(s: *stream, buf: []u8) (size | EOF | error) = { fn limit_write(s: *stream, buf: const []u8) (size | error) = { let stream = s: *limitstream; if (stream.limit == 0) { - return 0; + return 0z; }; let slice = if (len(buf) > stream.limit) { yield buf[..stream.limit]; diff --git a/io/types.ha b/io/types.ha @@ -4,8 +4,9 @@ use errors; // Returned by [[readitem]], [[readitems]] and [[readall]] if the I/O handle -// returned [[EOF]] prior to completely reading an item. -export type underread = !void; +// returned [[EOF]] prior to completely reading an item. Stores the amount that +// was succesfully read. +export type underread = !size; // Any error which may be returned from an I/O function. export type error = !(...errors::error | underread); diff --git a/io/util.ha b/io/util.ha @@ -13,7 +13,7 @@ export fn readitem(in: handle, item: *void, itemsz: size) (size | error) = { for (i < itemsz) { match (read(in, buf[..(itemsz - i)])) { case EOF => - return underread; + return i: underread: error; case let z: size => i += z; }; @@ -41,7 +41,7 @@ export fn readall(in: handle, buf: []u8) (size | EOF | error) = { if (z == 0) { return EOF; }; - return underread; + return z: underread: error; case let n: size => z += n; };