HP-UX Reference (11i v2 07/12) - 3 Library Functions A-M (vol 6)
f
fseek(3S) fseek(3S)
NAME
fseek(), fseeko(), ftell(), ftello(), rewind(), fseek_unlocked(), ftell_unlocked(), rewind_unlocked() - reposition a
file pointer in a stream
SYNOPSIS
#include <stdio.h>
int fseek(FILE *stream, long int offset, int whence);
int fseeko(FILE *stream, off_t offset, int whence);
void rewind(FILE *stream);
long int ftell(FILE *stream);
off_t ftello(FILE *stream);
Obsolescent Interfaces
int fseek_unlocked(FILE *stream, long int offset, int whence);
void rewind_unlocked(FILE *stream);
long int ftell_unlocked(FILE *stream);
DESCRIPTION
fseek() sets the file-position indicator for stream. The new position, measured in bytes from the begin-
ning of the file, is obtained by adding offset to the position specified by whence. The specified position is the
beginning of the file for
SEEK_SET, the current position for SEEK_CUR, or end-of-file for
SEEK_END.
fseeko() is a non-POSIX standard API provided by the _LARGEFILE_SOURCE
compile option. It is
identical to the
fseek() except that the offset parameter is an off_t instead of a
long int. All other
functional behaviors, returns, and errors are identical to the POSIX
fseek().
If the most recent operation, other than ftell(), on the stream is fflush(), the file offset in the
underlying open file description is adjusted to reflect the location specified by the
fseek().
rewind(stream) is equivalent to fseek (stream, 0L, SEEK_SET) , except that no value is
returned.
fseek() and rewind() undo any effects of ungetc(3S).
After fseek() or rewind(), the next operation on a file opened for update can be either input or out-
put. fseek() clears the EOF indicator for the stream. rewind() does an implicit clearerr() call
(see ferror(3S)).
ftell() returns the offset of the current byte relative to the beginning of the file associated with the
named stream.
ftello() is a non-POSIX standard API provided by the _LARGEFILE_SOURCE
compile option. It is
identical to the
ftell() except that it returns an off_t instead of a long int. All other behaviors,
returns, and errors are identical to the POSIX
ftell().
Obsolescent Interfaces
fseek_unlocked(), rewind_unlocked()
, and ftell_unlocked() reposition a file pointer in
astream.
RETURN VALUE
fseek() and fseek_unlocked() return zero if they succeed. Otherwise they return −1 and set
errno to indicate the error.
ftell() and ftell_unlocked() return the current value of the file position indicator for the stream
measured in bytes from the beginning of the file. Otherwise, ftell() and ftell_unlocked() return
−1 and set
errno to indicate the error.
rewind() and rewind_unlocked() do not return any value. Therefore, any application that needs
to detect errors should clear errno before calling rewind() or rewind_unlocked(). Then, upon
completion, if
errno is non-zero, it should assume an error has occurred.
444 Hewlett-Packard Company − 1 − HP-UX 11i Version 2: December 2007 Update