頭文件
#include<sys/types.h>#include<sys/stat.h>#include<unistd.h>
原型
intstat(constchar*pathname,struct stat *statbuf);intfstat(int fd,struct stat *statbuf);intlstat(constchar*pathname,struct stat *statbuf);//不追蹤(不穿透)
功能:
包含文件的詳細信息(所屬用戶、所屬組、權限等)
參數:
pathname 文件路徑
statbuf struct stat 類型結構體(上圖有)
返回值
成功返回0,失敗返回-1
struct stat 結構體
struct stat
{
dev_t st_dev;/* ID of device containing file */文件使用的設備號ID
ino_t st_ino;/* inode number */ 索引節點號
mode_t st_mode;/* protection */ 文件對應的模式,文件,目錄等(下圖)
nlink_t st_nlink;/* number of hard links */ 文件的硬連接數
uid_t st_uid;/* user ID of owner */ 所有者用戶識別號
gid_t st_gid;/* group ID of owner */ 組識別號
dev_t st_rdev;/* device ID (if special file) */ 設備文件的設備號
off_t st_size;/* total size, in bytes */ 以字節爲單位的文件容量
blksize_t st_blksize;/* blocksize for file system I/O */ 包含該文件的磁盤塊的大小
blkcnt_t st_blocks;/* number of 512B blocks allocated */ 該文件所佔的磁盤塊
time_t st_atime;/* time of last access */ 最後一次訪問該文件的時間
time_t st_mtime;/* time of last modification *//最後一次修改該文件的時間
time_t st_ctime;/* time of last status change */ 最後一次改變該文件狀態的時間
};