FSEEK - reposition I/O stream.
(ANSI Standard)
Usage:
#include <stdio.h>
ret = fseek( f, offset, from );
Where:
- FILE *f;
- points to the file on which I/O is to be repositioned.
- long offset;
- is an integer giving the number of bytes to move forward
or backward in the file. This may be positive or
negative, provided it makes sense (e.g. it does not make
sense to have a negative offset if you are starting at
the beginning of the file).
- int from;
- is one of the manifests SEEK_SET, SEEK_CUR, or SEEK_END
(see below).
- int ret;
- is non-zero if the seek operation was invalid (e.g. on a
file not opened with a "b" option); otherwise,
the return value is zero.
Description:
"fseek" repositions the I/O stream of the file
"f". If "f" is a binary stream:
- If "from" is SEEK_SET, "fseek" sets
things up so that the next input or output on
"f" will be "offset" bytes from the
beginning of the file.
- If "from" is SEEK_CUR, "fseek" sets
things up so the next input or output on "f"
will be "offset" bytes from the current
position in the file.
- If "from" is SEEK_END, "fseek" sets
things up so the next input or output on "f"
will be "offset" bytes from the end of the
file.
If "f" is a sequential stream:
- If "from" is SEEK_SET, the "offset"
can only be zero (representing the beginning of the file)
or a value returned by "ftell" representing
some other position in the file. This value won't
actually be a byte count, so you can't add or subtract
from it.
- If "from" is SEEK_CUR, the "offset"
must be zero (representing the current position in the
file).
- If "from" is SEEK_END, the "offset"
must be zero (representing the end of the file).
"fseek" undoes any effects of "ungetc";
see "expl c lib ungetc".
If you have a file opened for update and you want to switch
from reading to writing or vice versa, you must do an
"fseek" (or "rewind"
or some similar operation).
Notes:
You cannot perform "fseek" operations on terminals
or on SYSOUT.
"fseek" does not work on input streams which are
concatenations of several input files.
We recommend that you use the ANSI standard functions
"fsetpos" and "fgetpos" instead of
"fseek" and "ftell". The reason is that
"fseek" and "ftell" only use a long integer
(36 bits) to represent a position in a file; this is not adequate
to deal with all the positions in a large GCOS8 file. On the
other hand, "fgetpos" and "fsetpos" use a
larger information structure to represent file positions and can
deal with any size file.
See Also:
expl c lib ftell
expl c lib fopen
expl c lib fsetpos
expl c lib fgetpos
Copyright © 1996, Thinkage Ltd.