Esc

open_stream_file

procedureextensionexperimentalsince 0.36.1Source
  • macOS: open_stream_file works on macOS
  • Linux: open_stream_file works on Linux
  • Windows: open_stream_file works on Windows
  • Wasm: open_stream_file is not available on Wasm

Opens a POSIX byte stream (a terminal, FIFO, or /dev/stdin) for non-blocking reads. Unlike open_file, reads use the current position rather than pread. Close with close. Windows returns .UNSUPPORTED. Closing leaves stdin open and restores its status flags when the path duplicated a descriptor (/dev/fd on macOS). While open, that shared descriptor is non-blocking too; do not read it elsewhere concurrently.

Signature

open_stream_file :: (path: string) -> (Io_File, Io_Error)
Example
input, error := open_stream_file("/dev/stdin");
if error == .NONE {
    defer close(*input);
    lines := make_line_reader(reader_of(*input));
    defer free_line_reader(*lines);
    line, read_error := read_line(*lines);
}

See also