next up previous contents index
Next: 6.1.2 ISO Streams Up: 6.1 Input and Output Previous: 6.1 Input and Output   Contents   Index

6.1.1 I/O Stream Implementation

A user may note that XSB's I/O streams are small integers, but they should not be confused with the file descriptors used by the OS. The OS file descriptors are objects returned by the C open function; XSB I/O streams indices into the internal XSB table of open files and associated information. The OS does not know about XSB I/O streams, while XSB (obviously) does know about the OS file descriptors. An OS file descriptor may be returned by certain predicates (e.g. pipe_open/2 or user-defined I/O). In the former case, a file descriptor can be promoted to XSB stream by open/{3,4} and in the latter by using the predicate fd2iostream/2.

When it starts, XSB opens a number of standard I/O streams that it uses to print results, errors, debugging info, etc. The descriptors are described in the file prolog_includes/standard.h. This file provides the following symbolic definitions:

    #define STDIN            0
    #define STDOUT           1
    #define STDERR           2
    #define STDWARN          3    /* output stream for xsb warnings  */
    #define STDMSG           4    /* output for regular xsb messages */
    #define STDDBG           5    /* output for debugging info       */
    #define STDFDBK          6    /* output for XSB feedback
                                     (prompt/yes/no/Aborting/answers) */

    #define AF_INET     0     /* XSB-side socket request for Internet domain */
    #define AF_UNIX     1     /* XSB-side socket request for UNIX domain */
These definitions can be used in user programs, if the following is provided at the top of the source file:
    compiler_options([xpp_on]).
    #include "standard.h"
(Note: the XSB preprocessor is not invoked on clauses typed into an interactive XSB session, so the above applies only to programs loaded from a file using consult and such.)


next up previous contents index
Next: 6.1.2 ISO Streams Up: 6.1 Input and Output Previous: 6.1 Input and Output   Contents   Index
Terrance Swift 2007-10-05