commit a51a24853d5c04f976f36a4494d05029dd900866 parent d6c950e614241eee903f3ce11afefe2fb59f5756 Author: Drew DeVault <sir@cmpwn.com> Date: Thu, 11 Feb 2021 17:43:42 -0500 os: add must_fdstream Diffstat:
M | os/+linux/fdstream.ha | | | 8 | ++++++++ |
1 file changed, 8 insertions(+), 0 deletions(-)
diff --git a/os/+linux/fdstream.ha b/os/+linux/fdstream.ha @@ -55,6 +55,14 @@ export fn streamfd(s: *io::stream) (int | void) = { return stream.fd; }; +// Returns the file descriptor for a given [io::stream]. If there is no fd +// associated with this stream, abort. +export fn must_streamfd(s: *io::stream) int = { + assert(is_fdstream(s)); + let stream = s: *fd_stream; + return stream.fd; +}; + fn fd_read(s: *io::stream, buf: []u8) (size | io::EOF | io::error) = { let stream = s: *fd_stream; return match (rt::read(stream.fd, buf: *[*]u8, len(buf))) {