Sun Studio 12: Fortran Library Reference

1.4.13.1 fseek: Reposition a File on a Logical Unit

The function is called by:

INTEGER*4 fseek

n = fseek( lunit, offset, from )

lunit

INTEGER*4

Input 

Open logical unit 

offset

INTEGER*4

or

INTEGER*8

Input 

Offset in bytes relative to position specified by from

 

An INTEGER*8 offset value is required when compiled for a 64-bit environment. If a literal constant is supplied, it must be a 64-bit constant, for example: 100_8

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 fseek 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: fseek()—Reposition MyFile to two bytes from the beginning


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

Example: Same example in a 64-bit environment and compiled with -m64:


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