- 论坛徽章:
- 0
|
回复 #1 wenhuiwen 的帖子
http://gcc.gnu.org/onlinedocs/gfortran/STAT.html
Next: SUM, Previous: SRAND, Up: Intrinsic Procedures
6.201 STAT — Get file status
Description:
This function returns information about a file. No permissions are required on the file itself, but execute (search) permission is required on all of the directories in path that lead to the file.
The elements that are obtained and stored in the array BUFF:
buff(1) Device ID
buff(2) Inode number
buff(3) File mode
buff(4) Number of links
buff(5) Owner's uid
buff(6) Owner's gid
buff(7) ID of device containing directory entry for file (0 if not available)
buff( File size (bytes)
buff(9) Last access time
buff(10) Last modification time
buff(11) Last file status change time
buff(12) Preferred I/O block size (-1 if not available)
buff(13) Number of blocks allocated (-1 if not available)
Not all these elements are relevant on all systems. If an element is not relevant, it is returned as 0.
This intrinsic is provided in both subroutine and function forms; however, only one form can be used in any given program unit.
Standard:
GNU extension
Class:
Subroutine, function
Syntax:
CALL STAT(FILE,BUFF[,STATUS])
Arguments:
FILE The type shall be CHARACTER(*), a valid path within the file system.
BUFF The type shall be INTEGER(4), DIMENSION(13).
STATUS (Optional) status flag of type INTEGER(4). Returns 0 on success and a system specific error code otherwise.
Example:
PROGRAM test_stat
INTEGER, DIMENSION(13) :: buff
INTEGER :: status
CALL STAT("/etc/passwd", buff, status)
IF (status == 0) THEN
WRITE (*, FMT="('Device ID:', T30, I19)" buff(1)
WRITE (*, FMT="('Inode number:', T30, I19)" buff(2)
WRITE (*, FMT="('File mode (octal):', T30, O19)" buff(3)
WRITE (*, FMT="('Number of links:', T30, I19)" buff(4)
WRITE (*, FMT="('Owner''s uid:', T30, I19)" buff(5)
WRITE (*, FMT="('Owner''s gid:', T30, I19)" buff(6)
WRITE (*, FMT="('Device where located:', T30, I19)" buff(7)
WRITE (*, FMT="('File size:', T30, I19)" buff(
WRITE (*, FMT="('Last access time:', T30, A19)" CTIME(buff(9))
WRITE (*, FMT="('Last modification time', T30, A19)" CTIME(buff(10))
WRITE (*, FMT="('Last status change time:', T30, A19)") CTIME(buff(11))
WRITE (*, FMT="('Preferred block size:', T30, I19)") buff(12)
WRITE (*, FMT="('No. of blocks allocated:', T30, I19)") buff(13)
END IF
END PROGRAM
See also:
To stat an open file: FSTAT, to stat a link: LSTAT
例子通过了在solaris 10 x86 sun studio 12 的f90下编译运行。具体参数可能有所变化,查查Sun Studio 12: Fortran Library Reference 。
[ 本帖最后由 enod 于 2007-9-21 23:06 编辑 ] |
|