hare

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

commit d71de84c03a239ae23a384c08d5135def69016d3
parent 4447fdd8ce24e18e1c77ac3ba1683a86fa293c10
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  2 Feb 2021 21:21:59 -0500

Use static fd_streams for stdin et al

Diffstat:
Mos/+linux/fdstream.ha | 3++-
Mos/+linux/stdfd.ha | 11+++++++----
2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/os/+linux/fdstream.ha b/os/+linux/fdstream.ha @@ -44,7 +44,7 @@ export fn streamfd(s: *io::stream) (int | void) = { return stream.fd; }; -fn static_fdopen(fd: int, name: str, stream: *fd_stream) void = { +fn static_fdopen(fd: int, name: str, stream: *fd_stream) *io::stream = { stream.stream = io::stream { name = name, reader = &fd_read, @@ -52,6 +52,7 @@ fn static_fdopen(fd: int, name: str, stream: *fd_stream) void = { closer = &fd_close, }; stream.fd = fd; + return &stream.stream; }; fn fd_read(s: *io::stream, buf: []u8) (size | io::EOF | io::error) = { diff --git a/os/+linux/stdfd.ha b/os/+linux/stdfd.ha @@ -1,8 +1,11 @@ use io; +let static_stdin: fd_stream = fd_stream { ... }; +let static_stdout: fd_stream = fd_stream { ... }; +let static_stderr: fd_stream = fd_stream { ... }; + @init fn init_stdfd() void = { - // TODO: use static_fdopen for these - stdin = fdopen(0, "<stdin>"); - stdout = fdopen(1, "<stdout>"); - stderr = fdopen(2, "<stderr>"); + stdin = static_fdopen(0, "<stdin>", &static_stdin); + stdout = static_fdopen(1, "<stdout>", &static_stdout); + stderr = static_fdopen(2, "<stderr>", &static_stderr); };