头文件
#include
#include
函数定义
int stat(const char file_name, struct stat buf);
返回值
执行成功则返回0,失败返回-1,错误代码存于errno
错误代码
ENOENT 参数file_name指定的文件不存在
ENOTDIR 路径中的目录存在但却非真正的目录
ELOOP 欲打开的文件有过多符号连接问题,上限为16符号连接
EFAULT 参数buf为无效指针,指向无法存在的内存空间
EACCESS 存取文件时被拒绝
ENOMEM 核心内存不足
ENAMETOOLONG 参数file_name的路径名称太长
结构体内部
struct stat
{
dev_t st_dev; / ID of device containing file /文件使用的设备号
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 / 最后一次改变该文件状态的时间
};
