hare

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

commit a0252a33a8ca8a006b1e09412c8eaaa1bd7005b1
parent e46ba1931727f2ebefa851733b23bc8a9e841d05
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 31 Jan 2021 14:14:51 -0500

os: add streamfd function

Diffstat:
Mos/+linux/fdstream.ha | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/os/+linux/fdstream.ha b/os/+linux/fdstream.ha @@ -65,3 +65,13 @@ fn static_fdopen(fd: int, name: str, stream: *fd_stream) void = { }; stream.fd = fd; }; + +// Returns the file descriptor for a given [io::stream]. If there is no fd +// associated with this stream, void is returned. +export fn streamfd(s: *io::stream) (int | void) = { + if (s.reader != &fd_read) { + return void; + }; + let stream = s: *fd_stream; + return stream.fd; +};