FSEEK(S) UNIX System V FSEEK(S)
Name
fseek, rewind, ftell - reposition a file pointer in a stream
Syntax
#include <stdio.h>
#include <unistd.h>
int fseek (stream, offset, ptrname)
FILE *stream;
long offset;
int ptrname;
void rewind (stream)
FILE *stream;
long ftell (stream)
FILE *stream;
Description
The fseek function 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, from the
current position, or from the end of the file, according as
ptrname has the value 0, 1, or 2, which is defined in the
<unistd.h> header file as follows:
Name Description
SEEK_SET Set position equal to offset bytes.
SEEK_CUR Set position to current location plus offset.
SEEK_END Set position to EOF plus offset.
rewind(stream) is equivalent to fseek(stream, 0L, 0), except
that no value is returned.
fseek and rewind undo any effects of ungetc(S).
After fseek or rewind, the next operation on a file opened
for update may be either input or output.
ftell returns the offset of the current byte relative to the
beginning of the file associated with the named stream.
See Also
lseek(S), fopen(S), popen(S), stdio(S), ungetc(S)
Diagnostics
The fseek function 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(S).
Warning
Although on the UNIX system an offset returned by ftell is
measured in bytes, and it is permissible to seek to
positions relative to that offset, portability to non-UNIX
systems requires that an offset be used by fseek directly.
Arithmetic may not meaningfully be performed on such an
offset, which is not necessarily measured in bytes.
Standards Conformance
fseek, ftell and rewind are conformant with:
AT&T SVID Issue 2, Select Code 307-127;
The X/Open Portability Guide II of January 1987;
ANSI X3.159-198X C Language Draft Standard, May 13,
1988;
IEEE POSIX Std 1003.1-1988 with C Standard Language-
Dependent System Support;
and NIST FIPS 151-1.
(printed 6/20/89)