Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fseek(S) — OpenDesktop Software Development System 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fopen(S)

lseek(S)

popen(S)

stdio(S)

ungetc(S)


 fseek(S)                       6 January 1993                       fseek(S)


 Name

    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 opera-
    tion on the stream.  The new position is at the signed distance offset
    bytes from the position specified by ptrname, which can be SEEKCUR,
    SEEKEND or SEEKSET.  These positions are defined in the <unistd.h>
    header file as follows:


    Name        Action

    SEEKCUR    set position to current location plus offset

    SEEKEND    set position to EOF plus offset

    SEEKSET    set position equal to offset bytes

    rewind(stream) is equivalent to fseek(stream, 0L, SEEKSET), 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 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).

 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), lseek(S), popen(S), stdio(S), ungetc(S)

 Standards conformance

    fseek, ftell and rewind are conformant with:
    AT&T SVID Issue 2;
    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.


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026