FSEEK(3F) FSEEK(3F)
fseek, fseek64, ftell, ftell64 - reposition a file on a logical unit
integer function fseek (lunit, offset, from)
integer offset, from
integer function fseek64 (lunit, offset64, from)
integer *8 offset64
integer function ftell (lunit)
integer *8 function ftell64(lunit)
lunit must refer to an open logical unit. offset is an offset in bytes
relative to the position specified by from. Valid values for from are:
0 meaning `beginning of the file'
1 meaning `the current position'
2 meaning `the end of the file'
The value returned by fseek will be 0 if successful, a system error code
otherwise. (See perror(3F))
Ftell returns the current position of the file associated with the
specified logical unit. The value is an offset, in bytes, from the
beginning of the file. If the value returned is negative, it indicates
an error and will be the negation of the system error code. (See
perror(3F))
Fseek64 and ftell64 are identical in functionality to their 32 bit
counterparts except they can operate on files larger than 2 gigabytes in
some filesystems.
/usr/lib/libU77.a
fseek(3S), perror(3F)
MIPS Computer Systems
Page 1
FSEEK(3S) FSEEK(3S)
fseek, fseek64, rewind, ftell, ftell64 - reposition a file pointer in a
stream
#include <stdio.h>
int fseek (FILE *stream, long offset, int whence);
int fseek64 (FILE *stream, long long offset, int whence);
void rewind (FILE *stream);
long ftell (FILE *stream);
long long ftell64 (FILE *stream);
fseek sets the file position indicator for the stream pointed to by
stream. The new position, measured in bytes from the beginning of the
file, is obtained by adding offset to the position specified by whence.
SEEK_SET specified starting point is the beginning of the file plus
offset.
SEEK_CUR starting point is the current value of the file position
indicator plus offset.
SEEK_END specified starting point is the EOF of the file plus offset.
A successful call to fseek clears the end-of-file indicator for the
stream.
fseek allows the file position indicator to be set beyond the end of the
existing data in the file. If data is later written at this point,
subsequent reads of data in the gap will return zero until data is
actually written into the gap. fseek, by itself, does not extend the
size of the file.
rewind(stream) is equivalent to:
(void) fseek ( stream , 0L, SEEK_SET),
except that the error indicator for the stream is also cleared. Also,
rewind returns no value.
fseek and rewind undo any effects of ungetc(3S) on the indicated stream.
After fseek or rewind, the next operation on a file opened for update may
be either input or output.
Page 1
FSEEK(3S) FSEEK(3S)
If stream is writable and buffered data has not been written to the
underlying file, fseek and rewind cause the unwritten data to be written
to the file.
ftell returns the offset of the current byte relative to the beginning of
the file associated with the named stream.
The functions fseek64 and ftell64 are identical to fseek and ftell
respectively, except that fseek64 takes a long long as an argument and
ftell64 returns a long long. This allows the routines to set and return
the file position indicator for files larger than 2 Gigabytes.
lseek(2), fopen(3S), fsetpos(3S), popen(3S), stdio(3S), ungetc(3S).
fseek 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(3S).
The ANSI C Standard restricts the use of offsets, when stream refers to a
text file. When operating on these files, the value of offset must be
zero unless whence is SEEK_SET. This restriction is necessary as the
unit of offsets may not be bytes on some systems, and arithmetic may not
meaningfully be performed on them.
As the unit of offset on this system (and on most UNIX systems) is bytes
for text as well as for binary files, the restrictions indicated in the
ANSI C Standard are not enforced. Portable programs, however, should be
coded accordingly.
Users of the -n32 compilation model are directed to either use ftell64
and fseek64 or fgetpos and fsetpos in place of ftell and fseek. The
reason for this is because the offset argument to fseek, and the return
value from ftell are both typed as long, which is not sufficient to
express the maximum file length supported by the -n32 compilation model.
PPPPaaaaggggeeee 2222 [ Back ]
|