Fortran Library Reference

stat, lstat, fstat: Get File Status

These functions return the following information:

Both stat and lstat query by file name. fstat queries by logical unit.

stat: Get Status for File, by File Name

The function is called by:

INTEGER*4 stat

ierr = stat ( name, statb )

name

character*n

Input 

Name of the file 

statb

INTEGER*4

Output 

Status structure for the file, 13-element array  

Return value 

INTEGER*4

Output 

ierr=0: OK

ierr>0: Error code

Example 1: stat():


    character name*18 /'MyFile'/
    INTEGER*4 ierr, stat, lunit/1/, statb(13)
    open( unit=lunit, file=name )
    ierr = stat ( name, statb )
    if ( ierr .ne. 0 ) stop 'stat: error'
    write(*,*)'UID of owner = ',statb(5),', blocks = ',statb(13)
    end

fstat: Get Status for File, by Logical Unit

The function

INTEGER*4 fstat

ierr = fstat ( lunit, statb )

lunit

INTEGER*4

Input 

Logical unit number  

statb

INTEGER*4

Output 

Status for the file: 13-element array  

Return value 

INTEGER*4

Output 

ierr=0: OK

ierr>0: Error code

is called by:

Example 2: fstat():


    character name*18 /'MyFile'/
    INTEGER*4 fstat, lunit/1/, statb(13)
    open( unit=lunit, file=name )
    ierr = fstat ( lunit, statb )
    if ( ierr .ne. 0 ) stop 'fstat: error'
    write(*,*)'UID of owner = ',statb(5),', blocks = ',statb(13)
    end

lstat: Get Status for File, by File Name

The function is called by:

ierr = lstat ( name, statb )

name

character*n

Input 

File name  

statb

INTEGER*4

Output 

Status array of file, 13 elements 

Return value 

INTEGER*4

Output 

ierr=0: OK

ierr>0: Error code

Example 3: lstat():


    character name*18 /'MyFile'/
    INTEGER*4 lstat, lunit/1/, statb(13)
    open( unit=lunit, file=name )
    ierr = lstat ( name, statb )
    if ( ierr .ne. 0 ) stop 'lstat: error'
    write(*,*)'UID of owner = ',statb(5),', blocks = ',statb(13)
    end

Detail of Status Array for Files

The meaning of the information returned in the INTEGER*4 array statb is as described for the structure stat under stat(2).

Spare values are not included. The order is shown in the following table:

statb(1)

statb(2)

statb(3)

statb(4)

statb(5)

statb(6)

statb(7)

statb(8)

statb(9)

statb(10)

statb(11)

statb(12)

statb(13)

Device inode resides on  

This inode's number  

Protection  

Number of hard links to the file  

User ID of owner  

Group ID of owner  

Device type, for inode that is device  

Total size of file  

File last access time  

File last modify time  

File last status change time  

Optimal blocksize for file system I/O ops  

Actual number of blocks allocated  

See also stat(2), access(3F), perror(3F), and time(3F).

Note: the path names can be no longer than MAXPATHLEN as defined in <sys/param.h>.