11.3.39 close/[1,2]   ISO

Synopsis

close(+Stream)

close(+Stream, +Options)

closes the stream corresponding to Stream.

Arguments

Stream

stream_object, must be ground

Stream or file specification.

Options

list of term, must be ground

A list of zero or more of the following:

force(Boolean)

Specifies whether SICStus Prolog is to close the stream forcefully, even in the presence of errors (true), or not (false). The latter is the default. Currently this option has no effect.

direction(+Direction)

Direction is an atom specifying the direction or directions to close.

One of:

input

Close only the input direction, if open.

output

Close only the output direction, if open.

all

Close all directions. This is the default.

if stream is not open in the specified direction then the call to open/4 does nothing.

Closing a single direction is mainly useful when dealing with bidirectional streams, such as sockets.

Description

If Stream is a stream object, then if the corresponding stream is open, then it will be closed in the specified directions; otherwise, an error exception is raised.

If Stream is a file specification, then the corresponding stream will be closed in the specified directions, provided that the file was opened by see/1 or tell/1.

Exceptions

Stream errors (see ref-iou-sfh-est), plus:

instantiation_error

Options is not instantiated enough.

type_error

Options is not a proper list.

domain_error

Options contains an invalid option.

permission_error

File not opened by see/1 or tell/1.

domain_error

Stream is neither a filename nor a stream.

Examples

In this example, foo will be closed:

see(foo),
…
close(foo)

However, in this example, a permission error will be raised and foo will not be closed:

open(foo, read, S),
…
close(foo)

Here, close(S) should have been used.

See Also

see/1, tell/1, open/[3,4], ref-iou-sfh, lib-sockets.



Send feedback on this subject.