Download OCaml 4 Reference Guide

Transcript
Chapter 22. The unix library: Unix system calls
443
Reads complete as writes (depending on O_SYNC/O_DSYNC)
| O_SHARE_DELETE
Windows only: allow the file to be deleted while still open
The flags to Unix.openfile[22.1].
type file_perm = int
The type of file access rights, e.g. 0o640 is read and write for user, read for group, none for
others
val openfile : string -> open_flag list -> file_perm -> file_descr
Open the named file with the given flags. Third argument is the permissions to give to the
file if it is created. Return a file descriptor on the named file.
val close : file_descr -> unit
Close a file descriptor.
val read : file_descr -> string -> int -> int -> int
read fd buff ofs len reads len characters from descriptor fd, storing them in string
buff, starting at position ofs in string buff. Return the number of characters actually read.
val write : file_descr -> string -> int -> int -> int
write fd buff ofs len writes len characters to descriptor fd, taking them from string
buff, starting at position ofs in string buff. Return the number of characters actually
written. write repeats the writing operation until all characters have been written or an
error occurs.
val single_write : file_descr -> string -> int -> int -> int
Same as write, but attempts to write only once. Thus, if an error occurs, single_write
guarantees that no data has been written.
Interfacing with the standard input/output library
val in_channel_of_descr : file_descr -> Pervasives.in_channel
Create an input channel reading from the given descriptor. The channel is initially in binary
mode; use set_binary_mode_in ic false if text mode is desired.
val out_channel_of_descr : file_descr -> Pervasives.out_channel
Create an output channel writing on the given descriptor. The channel is initially in binary
mode; use set_binary_mode_out oc false if text mode is desired.
val descr_of_in_channel : Pervasives.in_channel -> file_descr
Return the descriptor corresponding to an input channel.
val descr_of_out_channel : Pervasives.out_channel -> file_descr
Return the descriptor corresponding to an output channel.