Go to main content
Oracle Developer Studio 12.6 Man Pages

Exit Print View

Updated: June 2017
 
 

fseek (3F)

Name

fseek, fseeko64, ftell, ftello64 - reposition a file on a logical unit

Synopsis

integer*4 function fseek (lunit, offset, from)
  integer*4 lunit
  integer*4 offset
  integer*8 offset in 64-bit environments
  integer*4 from
integer*4 function fseeko64 (lunit, offset, from)
  integer*4 lunit
  integer*8 offset
  integer*4 from
integer*4 function ftell (lunit)
  integer*4 lunit
integer*8 function ftello64 (lunit)
  integer*4 lunit

Description

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

the beginning of the file

1

the current position

2

the end of the file

The value returned by fseek is 0 if successful, a system error code otherwise. See perror(3F).

The function 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 is the negation of the system error code. See perror(3F).

The offset returned by ftell can be used by fseek at a later time in the program to reposition the file to that same place for reading.

CAUTION: On sequential files, following a call to fseek by an output operation (e.g. WRITE) causes all data records following the new position to be deleted and replaced by the new data record (and an end-of-file mark). Rewriting a record in place can only be done with direct access files.

fseeko64 and ftello64 operate identically to fseek and ftell respectively, except that the first two routines will operate on "large files" as well -- files with size in bytes greater than the range of INTEGER*4 data (2 Gb). Large file support was introduced with the Solaris 2.6 operating environment.

When used with a large file, the variable receiving the result from ftello64 must also be declared INTEGER*8 to avoid truncation.

Notes

When compiled to run in a 64-bit environment (with the compiler option -m64 the offset variable passed to fseek must be declared INTEGER*8.

The 64-bit versions, fseeko64 and ftello64, are provided to make portability between 32-bit and 64-bit environments easier.

Files

libfsu.a

See Also

fseek(3C), perror(3F)