Os.FdFile descriptors operations.
unix_buffer_size is the value of the OCaml runtime system buffer size for I/O operations.
Available in 5.4 as Sys.io_buffer_size.
close_noerr fd uses Unix.close on fd, retries on EINTR and silently catches any error it may raise. Typically used with Fun.protect.
copy ~buf src ~dst reads src and writes it to dst using buf as a buffer; if unspecified a buffer of length unix_buffer_size is created for the call. Raise Unix.Unix_error if that happens.
to_string fd reads fd to a string. Raises Unix.Unix_error in case of error.
read_file fn fd reads fd to a string assuming it is a file descriptor open on file path fn. Raises Failure in case of error with an error message that mentions fn.
read fd b ~first ~length reads at most length bytes of fd into b starting at first. Raises Unix.Unix_error but handles Unix.EINTR.
write fd b ~first ~length writes length byte of b starting at first on fd. Returns when the bytes have been fully written. Raises Unix.Unix_error but handles Unix.EINTR.
write_string fd s is like write but write the string s.
openpty () allocates a pseudoterminal device pair (pty, tty) with:
pty the (controlling) pseudoterminal device.tty the (controlled) terminal device. Usually plugged into the stdio of a spawned process.Note. Both file descriptor have close on exec set to true. But if any of these is given to a spawn's stdio explicitely, it survives closure.
See also More.Os.Pty.
TODO. Implement on Windows using conPTY.