fseek(3S) fseek(3S)NAME fseek, rewind, ftell - reposition a file pointer in a stream SYNOPSIS #include <stdio.h> int fseek(stream, offset, ptrname) FILE *stream; long offset; int ptrname; void rewind(stream) FILE *stream; long ftell(stream) FILE *stream; DESCRIPTION fseek sets the position of the next input or output opera- tion on the stream. The new position is at the signed dis- tance offset bytes from the beginning, the current position, or the end of the file, when the value of ptrname is 0, 1, or 2, respectively. rewind(stream) is equivalent to fseek(stream,0L,0), 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 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. RETURN VALUE fseek returns non-zero for improper seeks; otherwise it re- turns 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). SEE ALSO lseek(2), fopen(3S), popen(3S), ungetc(3S). WARNINGS On A/UX an offset returned by ftell is measured in bytes, and it is permissible to seek to positions relative to that offset; however, portability to systems other than A/UX re- quires that an offset be used by fseek directly. Arithmetic April, 1990 1
fseek(3S) fseek(3S)may not meaningfully be performed on such an offset, which is not necessarily measured in bytes. 2 April, 1990