hare

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

commit b973201ced3b33705b90e07a0f4a45276655a655
parent 9ae566de930c1264b077d35fbda5156e5f6fdc26
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed, 17 Mar 2021 11:36:51 -0400

bufio: add is_buffered, has_buffered

Diffstat:
Mbufio/buffered.ha | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/bufio/buffered.ha b/bufio/buffered.ha @@ -81,6 +81,22 @@ export fn set_flush_bytes(s: *io::stream, b: []u8) void = { s.flush = b; }; +// Returns true if this is a buffered stream. +export fn is_buffered(s: *io::stream) bool = { + return s.closer == &buffered_close; +}; + +// Returns true if this stream or any underlying streams are buffered. +export fn is_buffered_any(s: *io::stream) bool = { + for (!is_buffered(s)) { + s = match (io::source(s)) { + io::unsupported => return false, + s: *io::stream => s, + }; + }; + return true; +}; + fn buffered_close(s: *io::stream) void = { assert(s.closer == &buffered_close); let s = s: *bufstream;