Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

lseek(2V)

fopen(3V)

popen(3S)

ungetc(3S)

FSEEK(3S)  —  STANDARD I/O FUNCTIONS

NAME

fseek, ftell, rewind − reposition a stream

SYNOPSIS

#include <stdio.h>

fseek(stream, offset, ptrname)
FILE ∗stream;
long offset;

long ftell(stream)
FILE ∗stream;

rewind(stream)
FILE ∗stream;

DESCRIPTION

fseek() 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, the current position, or the end of the file, according as ptrname has the value 0, 1, or 2. 

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. 

SEE ALSO

lseek(2V), fopen(3V), popen(3S), ungetc(3S)

DIAGNOSTICS

fseek() returns −1 for improper seeks, otherwise zero.  An improper seek can be, for example, an fseek() done on a file associated with a non-seekable device, such as a tty or a pipe; in particular, fseek() may not be used on a terminal, or on a file opened using popen(3S). 

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 a (non-UNIX) system 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. 

Sun Release 4.1  —  Last change: 6 October 1987

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