DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

fseek(S-osr5)


fseek, ftell, rewind -- reposition a file pointer in a stream

Syntax

cc . . . -lc

#include  <stdio.h>
#include  <unistd.h>

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

long ftell (stream) FILE *stream;

void rewind (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 position specified by ptrname, which can be SEEK_CUR, SEEK_END or SEEK_SET. These positions are defined in the <unistd.h> header file as follows:


Name
Action


SEEK_CUR
set position to current location plus offset


SEEK_END
set position to EOF plus offset


SEEK_SET
set position equal to offset bytes

rewind(stream) is equivalent to fseek(stream, 0L, SEEK_SET), except that no value is returned.

fseek and rewind undo any effects of ungetc(S-osr5).

After fseek or rewind, the next operation on a file opened for update can 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.

Diagnostics

The fseek function returns zero for correct seeks and non-zero for improper seeks, such as an fseek done on a file not opened via fopen. fseek also cannot be used on a terminal or on a file opened via popen(S-osr5).

Warning

On System V/386, an offset returned by ftell is measured in bytes, and it is permissible to seek to positions relative to that offset. However, portability to non-UNIX type systems requires that an offset be used by fseek directly. You cannot perform arithmetic on such an offset, which is not necessarily measured in bytes.

See also

fopen(S-osr5), lseek(S-osr5), popen(S-osr5), stdio(S-osr5), ungetc(S-osr5)

Standards conformance

fseek, ftell and rewind are conformant with:

X/Open Portability Guide, Issue 3, 1989 ;
ANSI X3.159-1989 Programming Language -- C ;
Intel386 Binary Compatibility Specification, Edition 2 (iBCSe2) ;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1) ;
and NIST FIPS 151-1 .


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005