Low Level I/O Functions

For each new stream the appropriate low level I/O functions have to be defined. Error handling, prompt handling and character counting is handled in a layer above these functions. They all operate on a user defined private data structure pointed out by user_handle in SP_stream.

User defined low level I/O functions may invoke Prolog code and use most of the support functions described in the other sections of this chapter. They must not use SP_fail() or SP_raise_exception(), doing so will not have the intended effect and may cause problems.

int my_fgetc(void *handle)
Should return the character read or -1 on end of file.
int my_fputc(char c, void *handle)
Should write the character c and return the character written.
int my_flush(void *handle)
Should flush the (output) stream and return 0 on success, -1 on error.
int my_eof(void *handle)
Should return 1 on end of file, else 0.
void my_clrerr(void *handle)
Should reset the stream's error and EOF indicators.
int my_close(void *handle)
Should close the stream and return zero.