hare

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

commit 5352057e0371b0beaae118b4ca49fd10d6ccff1a
parent e4ada638847880bfafcc2aa82407b2bdcdeef97c
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu,  5 May 2022 13:15:00 +0200

bufio::flush: accept any io::handle

Fixes: https://todo.sr.ht/~sircmpwn/hare/667
Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mbufio/buffered.ha | 11++++++++++-
Mcmd/hare/subcmds.ha | 2+-
Mos/+linux/stdfd.ha | 4++--
3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/bufio/buffered.ha b/bufio/buffered.ha @@ -79,7 +79,16 @@ export fn buffered( }; // Flushes pending writes to the underlying stream. -export fn flush(s: *bufstream) (io::error | void) = { +export fn flush(s: io::handle) (io::error | void) = { + let s = match (s) { + case let st: *io::stream => + if (st.writer != &buffered_write) { + return errors::unsupported; + }; + yield st: *bufstream; + case => + return errors::unsupported; + }; if (s.wavail == 0) { return; }; diff --git a/cmd/hare/subcmds.ha b/cmd/hare/subcmds.ha @@ -546,7 +546,7 @@ fn version(args: []str) void = { fmt::printfln("HAREPATH\t{}", items)!; case let env: str => fmt::printf("HAREPATH\t")!; - bufio::flush(&os::stdout_bufio)!; + bufio::flush(os::stdout)!; fmt::errorf("(from environment)")!; const items = strings::split(env, ":"); defer free(items); diff --git a/os/+linux/stdfd.ha b/os/+linux/stdfd.ha @@ -4,12 +4,12 @@ use bufio; use io; -export let stdin_bufio: bufio::bufstream = bufio::bufstream { +let stdin_bufio: bufio::bufstream = bufio::bufstream { source = 0, ... }; -export let stdout_bufio: bufio::bufstream = bufio::bufstream { +let stdout_bufio: bufio::bufstream = bufio::bufstream { source = 1, ... };