FSEEK(3S)FSEEK(3S)NAME
fseek, ftell, rewind, fgetpos, fsetpos - reposition a stream
SYNOPSIS
#include <stdio.h>
int fseek(FILE *stream, long int offset, int whence);
long int ftell(FILE *stream);
void rewind(FILE *stream);
int fgetpos(FILE *stream, fpos_t *pos);
int fsetpos(FILE *stream, const fpos_t *pos);
DESCRIPTION
Fseek sets the position of the next input or output operation on the
stream. The new position is at the signed distance offset bytes from
the beginning, the current position, or the end of the file, according
as whence has the value SEEK_SET, SEEK_CUR, or SEEK_END. Fseek undoes
any effects of ungetc(3S).
Ftell returns the current value of the offset relative to the beginning
of the file associated with the named stream. It is measured in bytes
on UNIX; on some other systems it is a magic cookie, and the only
foolproof way to obtain an offset for fseek.
Fgetpos stores the current value of the file position indicator for the
stream pointed to by stream in the object pointed to by pos. The value
stored contains unspecified information usable by the fsetpos function
for repositioning the stream to its position at the time of the call to
the fgetpos function.
Fsetpos sets the file position indicator for the stream pointed to by
stream according to the value of the object pointed to by pos, which
must be value returned by an earlier call to fgetpos on the same
stream. A successful call clears the end-of-file indicator for the
stream and undoes any effects of the ungetc function on the same
stream. After call on an update stream, the next operation may be
either input or output.
Rewind(stream) is equivalent to: “(void) fseek (stream, 0L, SEEK_CUR)”
RETURN VALUE
Fseek returns zero if successful, otherwise -1.
Ftell returns the current value of the file position indicator for the
stream, otherwise -1L is returned.
Both fseek and ftell stores an error code in errno when unsuccessful.
ERRORS
The underlying functions of fseek and ftell are write(2) and lseek(2).
The error conditions specified for write(2) and lseek(2) apply to fseek
and ftell.
SEE ALSOlseek(2), write(2), fopen(3S)
August 1, 1992 FSEEK(3S)