Developer Guide and Reference

ID 767251
Date 10/31/2024
Public
Document Table of Contents

STAT

Portability Function: Returns detailed information about a file.

Module

USE IFPORT

result = STAT (name,statb)

name

(Input) Character*(*). Name of the file to examine.

statb

(Output) INTEGER(4) or INTEGER(8). One-dimensional array of size 12; where the system information is stored. The elements of statb contain the following values:

Element

Description

Values or Notes

statb(1)

Device the file resides on

Windows: Always 0

Linux: System dependent

statb(2)

File inode number

Windows: Always 0

Linux: System dependent

statb(3)

Access mode of the file

See the table in Results

statb(4)

Number of hard links to the file

Windows: Always 1

Linux: System dependent

statb(5)

User ID of owner

Windows: Always 1

Linux: System dependent

Results

The result type is INTEGER(4).

On Windows* systems, the result is zero if the inquiry was successful; otherwise, the error code ENOENT (the specified file could not be found). On Linux* systems, the file inquired about must be currently connected to a logical unit and must already exist when STAT is called; if STAT fails, errnois set.

For a list of other error codes, see IERRNO.

The access mode (the third element of statb) is a bitmap consisting of an IOR of the following constants:

Symbolic name

Constant

Description

Notes

S_IFMT

O'0170000'

Type of file

S_IFDIR

O'0040000'

Directory

S_IFCHR

O'0020000'

Character special

Never set on Windows systems

S_IFBLK

O'0060000'

Block special

Never set on Windows systems

S_IFREG

O'0100000'

Regular

STAT returns the same information as FSTAT, but accesses files by name instead of external unit number.

On Windows* systems, LSTAT returns exactly the same information as STAT. On Linux systems, if the file denoted by name is a link, LSTAT provides information on the link, while STAT provides information on the file at the destination of the link.

You can also use the INQUIRE statement to get information about file properties.

Example

USE IFPORT CHARACTER*12 file_name INTEGER(4) info_array(12) print *, 'Enter file to examine: ' read *, file_name ISTATUS = STAT (file_name, info_array) if (.not. istatus) then print *, info_array else print *, 'Error = ',istatus end if end