stream_code/2

Synopsis

stream_code(-Stream, +CStream)

stream_code(+Stream, -CStream)

Converts between Prolog representation, Stream, and C representation, CStream, of a stream.

Arguments


Stream stream_object
a variable or a valid Prolog stream
CStream integer
a variable or a valid C stream

Description

stream_code/2 is used when there are input/output related operations performed on the same stream in both Prolog code and foreign code.

Stream argument is a valid type if it is user, user_input, user_output, user_error, a variable, or a value obtained through open/[3,4] or previous stream_code/2 call. Such a valid Stream value can be used as the stream argument to any of the Prolog built-in I/O predicates taking a stream argument.

CStream argument is a valid type if it is a variable, a value obtained through previous stream_code/2 call, a value obtained through QP_fopen(), QP_fdopen(), or a value of pointer to QP_stream structure obtained through foreign function call. Such a valid CStream value can be used as the stream argument to any of the QP foreign function taking stream as an argument.

Exceptions


instantiation_error
Stream argument or CStream argument is not ground.
type_error
Stream or CStream is not a stream type or CStream is not an integer type.
existence_error
Stream is syntactically valid but does not name an open stream or CStream is of integer type but does not name a pointer to a stream.

Comments

The most frequent use of stream_code/2 is to get a stream value to be used in Prolog code for a stream created in foreign code. This is necessary when a desired stream can not be obtained through open/[3,4]; e.g. a stream referring to a socket or an encrypted file.

See Also:

open/[3,4], QP_fopen(), QP_fdopen()