fseeko(3S)


fseeko, fseeko64, ftello, ftello64 -- reposition a file pointer in a stream

Synopsis

   #include <stdio.h>
   

int fseeko(FILE *stream, off_t offset, int ptrname);

int fseeko64(FILE *stream, off64_t offset, int ptrname);

off_t ftello(FILE *stream);

off64_t ftello64(FILE *stream);

Description

fseeko sets the position of the next input or output operation on the stream (see intro(3)). The new position is at the signed distance offset bytes from the beginning, from the current position, or from the end of the file, according to a ptrname value of SEEK_SET, SEEK_CUR, or SEEK_END (defined in stdio.h) as follows:


SEEK_SET
set position equal to offset bytes.

SEEK_CUR
set position to current location plus offset.

SEEK_END
set position to EOF plus offset.

fseeko 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. fseeko, by itself, does not extend the size of the file.

fseek clears the EOF indicator and undoes any effects of ungetc on stream. After fseek, the next operation on a file opened for update may be either input or output.

If stream is writable and buffered data has not been written to the underlying file, fseek causes the unwritten data to be written to the file.

ftello returns the offset of the current byte relative to the beginning of the file associated with the named stream.

Errors

fseeko and fseeko64 return -1 for improper seeks, otherwise zero. An improper seek can be, for example, an fseeko or an fseeko64 done on a file that has not been opened via fopen or fopen64; in particular, fseeko and fseeko64 may not be used on a terminal or on a file opened via popen. After a stream is closed, no further operations are defined on that stream.

fseeko and ftello fail when the resulting file offset would be a value which cannot be represented correctly in an object of type off_t.

References

fopen(3S), intro(2), Intro(3S), lseek(2), popen(3S), ungetc(3S), write(2)

Notices

Although on the UNIX system an offset returned by ftello is measured in bytes, and it is permissible to seek to positions relative to that offset, portability to non-UNIX systems requires that an offset be used by fseeko directly. Arithmetic may not meaningfully be performed on such an offset, which is not necessarily measured in bytes.

Considerations for large file support

fseeko64 and ftello64 support large files, but are otherwise identical to fseeko and ftello, respectively. For details on programming for large file capable applications, see ``Large File Support'' on intro(2).
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004