FSEEK(3S)                                                            FSEEK(3S)


NAME
     fseek, fseek64, rewind, ftell, ftell64 - reposition a file pointer in a
     stream

SYNOPSIS
     #include <stdio.h>

     int fseek (FILE *stream, long offset, int whence);

     int fseek64 (FILE *stream, long long offset, int whence);

     void rewind (FILE *stream);

     long ftell (FILE *stream);

     long long ftell64 (FILE *stream);

DESCRIPTION
     fseek sets the file position indicator for the stream pointed to by
     stream.  The new position, measured in bytes from the beginning of the
     file, is obtained by adding offset to the position specified by whence.

     SEEK_SET    specified starting point is the beginning of the file plus
                 offset.

     SEEK_CUR    starting point is the current value of the file position
                 indicator plus offset.

     SEEK_END    specified starting point is the EOF of the file plus offset.

     A successful call to fseek clears the end-of-file indicator for the
     stream.

     fseek allows the file position indicator to be set beyond the end of the
     existing data in the file.  If data is later written at this point,
     subsequent reads of data in the gap will return zero until data is
     actually written into the gap.  fseek, by itself, does not extend the
     size of the file.

     rewind(stream) is equivalent to:

          (void) fseek ( stream , 0L, SEEK_SET),

     except that the error indicator for the stream is also cleared.  Also,
     rewind returns no value.

     fseek and rewind undo any effects of ungetc(3S) on the indicated stream.
     After fseek or rewind, the next operation on a file opened for update may
     be either input or output.


     If stream is writable and buffered data has not been written to the
     underlying file, fseek and rewind cause the unwritten data to be written
     to the file.

     ftell returns the offset of the current byte relative to the beginning of
     the file associated with the named stream.

     The functions fseek64 and ftell64 are identical to fseek and ftell
     respectively, except that fseek64 takes a long long as an argument and
     ftell64 returns a long long.  This allows the routines to set and return
     the file position indicator for files larger than 2 Gigabytes.

SEE ALSO
     lseek(2), fopen(3S), fsetpos(3S), popen(3S), stdio(3S), ungetc(3S).

DIAGNOSTICS
     fseek returns non-zero for improper seeks, otherwise zero.  An improper
     seek can be, for example, an fseek done on a file that has not been
     opened via fopen; in particular, fseek may not be used on a terminal, or
     on a file opened via popen(3S).

WARNING
     The ANSI C Standard restricts the use of offsets, when stream refers to a
     text file.  When operating on these files, the value of offset must be
     zero unless whence is SEEK_SET.  This restriction is necessary as the
     unit of offsets may not be bytes on some systems, and arithmetic may not
     meaningfully be performed on them.
     As the unit of offset on this system (and on most UNIX systems) is bytes
     for text as well as for binary files, the restrictions indicated in the
     ANSI C Standard are not enforced.  Portable programs, however, should be
     coded accordingly.

     Users of the -n32 compilation model are directed to either use ftell64
     and fseek64 or fgetpos and fsetpos in place of ftell and fseek. The
     reason for this is because the offset argument to fseek, and the return
     value from ftell are both typed as long, which is not sufficient to
     express the maximum file length supported by the -n32 compilation model.


                                                                        Page 2