ISO
open/1 creates a stream for the source or sink designated in
SourceSink, and binds Stream to a structure representing
that stream.
- If SourceSink is an atom, or the term file(File)
where File is an atom, the stream is a file stream. In this
case Mode can be
- read to create an input stream. In Windows, whether the
file is textual or binary is determined by the file's properties.
- write to create an output stream. Any previous file with
a similar path is removed and a (textual) file is created which becomes
a record of the output stream.
- write_binary to create an output stream. Any previous file with
a similar path is removed and a file is created which becomes
a record of the output stream. The file created is binary in Windows,
while in UNIX write_binary has the same effect as write.
- append to create an output stream. In this case the
output stream is appended to the contents of the file, if it exists,
and otherwise a new file is created for (textual) output
- append_binary to create an output stream. In this case the
output stream is appended to the contents of the file, if it exists,
and otherwise a new file is created for (binary) output
- If SourceSink is the term atom(Atom) where Atom is an atom, the stream is an atom stream. In this case Mode currently can only be read. This stream class, which
reads from interned atoms, is analogous to C's sscanf()
function.
- If SourceSink is the term pipe(FIleDescriptor)
where FileDescriptor is an integer, then a pipe stream is opened
in the mode for FileDescriptor.
ISO Compatability Note: This predicate extends the ISO definition of open/3 to include strings and pipes as well as the file modes write_binary and append_binary.
Error Cases
- SourceSink or Mode is not instantiated
- Mode is not a valid I/O mode
- domain_error(io_mode,Mode)
- SourceSink is a file and cannot be opened, or opened in
the desired mode
- permission_error(open,file,SourceSink)