HP C/iX Library Reference Manual (30026-90004)

Chapter 5 183
HP C/iX Library Function Descriptions
fseek
fseek
Positions the next I/O operation on an open stream to a new position relative to the current
position.
Syntax
#include <stdio.h>
int fseek (FILE *
stream
, long int
offset
, int
ptrname
);
Parameters
stream
A pointer to an open stream.
offset
The number of bytes to skip over. The
offset
parameter can be negative
or positive, indicating backward or forward movement in the file,
respectively.
ptrname
The reference point in the file from which
offset
bytes are measured.
Return Values
0 Success.
1 An error occurred, and errno is set to indicate the error condition.
Description
The fseek function sets the file position indicator for the stream pointed to by
stream
.
For a binary stream, the new position, measured in characters from the beginning of the
file, is obtained by adding
offset
to the position specified by
whence
. The specified
position is:
The beginning of the file if
whence
is SEEK_SET.
The current value of the file position indicator if
whence
is SEEK_CUR.
The end-of-file if
whence
is SEEK_END.
For a text stream, either
offset
is zero, or
offset
is a value returned from a previous call
to ftell() on the same stream, and
whence
is SEEK_SET.
A successful call to fseek() clears the end-of-file indicator for the stream and undoes any
effect of ungetc() on the same stream. After an fseek() call, the next operation on an
update stream can be either input or output.
NOTE
If linking with the POSIX/iX library, fseek() allows the file offset to be set
beyond the end of the existing data in the file. If data is written at this point,
the gap between the old and new end-of-file is zero filled. However, fseek()
cannot by itself extend the size of the file.