Sun Studio 12: Fortran Library Reference

1.4.14 fseeko64, ftello64: Determine Position and Reposition a Large File

fseeko64 and ftello64 are "large file" versions of fseek and ftell. They take and return INTEGER*8 file position offsets. (A "large file" is larger than 2 Gigabytes and therefore a byte-position must be represented by a 64-bit integer.) Use these versions to determine and/or reposition large files.

1.4.14.1 fseeko64: Reposition a File on a Logical Unit

The function is called by:

INTEGER fseeko64

n = fseeko64( lunit, offset64, from )

lunit

INTEGER*4

Input 

Open logical unit 

offset64

INTEGER*8

Input 

64-bit offset in bytes relative to position specified by from

from

INTEGER*4

Input 

0=Beginning of file 

1=Current position 

2=End of file 

Return value 

INTEGER*4

Output 

n=0: OK; n>0: System error code


Note –

On sequential files, following a call to fseeko64 by an output operation (for example, WRITE) causes all data records following the fseek 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.


Example: fseeko64()—Reposition MyFile to two bytes from the beginning:


       INTEGER fseeko64, lunit/1/, from/0/, n
       INTEGER*8 offset/200/
       open( UNIT=lunit, FILE=’MyFile’ )
       n = fseeko64( lunit, offset, from )
       if ( n .gt. 0 ) stop ’fseek error’
       end

1.4.14.2 ftello64: Return Current Position of File

The function is called by:

INTEGER*8 ftello64

n = ftello64( lunit )

lunit

INTEGER*4

Input 

Open logical unit 

Return value 

INTEGER*8

Output 

n≥0: n=Offset in bytes from start of file

n<0: n=System error code

Example: ftello64():


       INTEGER*8 ftello64, lunit/1/, n
       open( UNIT=lunit, FILE=’MyFile’ )
       ...
       n = ftello64( lunit )
       if ( n .lt. 0 ) stop ’ftell error’
       ...