Sun Studio 12:Fortran 库参考

1.4.48 statlstatfstat:获取文件状态

这些函数返回以下信息:

statlstat 都是按文件名查询。fstat 是按逻辑单元查询。

1.4.48.1 stat:按文件名获取文件状态

该函数的调用方式如下所示:

INTEGER*4 stat

ierr = stat ( name, statb )

name

character*n

输入 

文件的名称 

statb

INTEGER*4

输出 

文件的状态结构,由 13 个元素组成的数组 

返回值 

INTEGER*4

输出 

ierr=0:OK

ierr>0:错误代码

示例 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),’,
     1   blocks = ’,statb(13)
       end

1.4.48.2 fstat:按逻辑单元获取文件状态

该函数的调用方式如下所示:

INTEGER*4 fstat

ierr = fstat ( lunit, statb )

lunit

INTEGER*4

输入 

逻辑单元编号 

statb

INTEGER*4

输出 

文件的状态:由 13 个元素组成的数组 

返回值 

INTEGER*4

输出 

ierr=0:OK

ierr>0:错误代码

示例 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),’,
     1      blocks = ’,statb(13)
       end

1.4.48.3 lstat:按文件名获取文件状态

该函数的调用方式如下所示:

ierr = lstat ( name, statb )

name

character*n

输入 

文件名 

statb

INTEGER*4

输出 

文件夹的状态数组,共 13 个元素 

返回值 

INTEGER*4

输出 

ierr=0:OK

ierr>0:错误代码

示例 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),’,
     1   blocks = ’,statb(13)
       end

1.4.48.4 文件状态数组的详细信息

INTEGER*4 数组 statb 中返回的信息的含义在 stat(2) 的 stat 结构中进行了介绍。

备用值不包括在内。顺序如下表所示:

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)

索引节点所在的设备 

相应索引节点的编号 

保护 

文件的硬链接数 

属主的用户 ID 

属主的组 ID 

属于设备的索引节点的设备类型 

文件的总大小 

上次访问文件的时间 

上次修改文件的时间 

上次更改文件状态的时间 

文件系统 I/O 操作的最佳块大小 

分配的实际块数 

另请参见 stat(2)、access(3F)、perror(3F) 和 time(3F)。

注意:路径名长度不能超过 <sys/param.h> 中定义的 MAXPATHLEN 值。