QP_seek()
#include <quintus/quintus.h> int QP_seek(stream, offset, whence) QP_stream *stream; long int offset; int whence;
Seeks to an arbitrary byte position on the stream.
QP_BEGINNING
QP_CURRENT
QP_END
The new position in bytes from the beginning of the file stream is stored in magic field of stream. It is stream->magic.byteno under UNIX.
If stream is an output stream permitting flushing output,
the characters in the buffer of the stream is flushed through
QP_flush()
before seek is performed.
If the stream does not permit flushing
output and there are characters remaining in the output buffer,
it is an error to seek. If stream is an input stream,
the characters in the input buffer of the stream are discarded
before seek is performed. The input buffer is empty when QP_seek()
returns.
QP_SUCCESS
QP_ERROR
QP_errno
and stream->errno.
QP_E_INVAL
QP_BEGINNING
, QP_CURRENT
, or
QP_END
.
QP_E_CANT_SEEK
Errors from QP_flush()
Errors from host operating system
QP_seek(
stream, 0L, QP_CURRENT)
sets the current position to
the magic field of stream. It does not change the position of
stream, but the side effect of flushing output and clearing
buffer also takes place.
The seek type in stream must permits seeking by bytes, i.e.
the seek_type field in stream is QP_SEEK_BYTE
.
So stream is created by defining a private stream and setting
seek_type field to QP_SEEK_BYTE
, opening a Prolog stream with
seek(byte) option in open/4
,
or opening a binary stream through QP_fopen()
or QP_fdopen()
.
Get the current byte offset from beginning of the file stream.
if (QP_seek(stream, 0L, QP_CURRENT) != QP_SUCCESS) QP_perror(stream->errno, "QP_seek"); else location = stream->magic.byteno;
QP_getpos()
, QP_setpos()
,
QP_rewind()
, QP_flush()
.
fli-ios