9.6.2.3 Internal Representation

For most streams you don't have to know anything about the internal representatio, but there may be occasions when you have to set some fields manually or do some processing on all streams of a particular type. SICStus Prolog maintains a circular list of stream objects of type SP_stream.

SP_stream *backward;
SP_stream *forward;
Used for linking streams together. The insertion is done by SP_make_stream() and the deletion is done from the Prolog predicate close/1.
char *filename;
This field is set to the empty string, "", by SP_make_stream(). May be set to a suitable encoded string, provided the string will not be overwritten until the stream is closed.
unsigned long mode;
A bit vector that contains information about the access modes supported, if the stream is a TTY stream etc. It is not available to the user but the TTY property can be set by the function:
void SP_set_tty(SP_stream *s)

int fd;
The file descriptor if the stream is associated with a file, socket etc. Otherwise a negative integer.
void *user_handle;
This is the pointer to the user supplied private data for the stream. For example, in the case of SICStus Prolog predefined file streams the user_handle could be a pointer to the standard I/O FILE.

There is no standard way to tell if a stream is user defined. You have to save pointers to the streams created or check if one of the stream functions installed is user defined, i.e:

     int is_my_stream(SP_stream *s)
     {
       return (s->sclose == my_close);
     }