5.Linux文件系统相关函数stat

stat函数原型:

int stat(const char* pathname, struct stat* buf);

pathname: 目标文件的路径
buf: struct stat结构体指针,用来保存返回的文件信息
返回值: 0表示执行成功,否则失败。失败后会改写 errno 这个全局变量,可以使用 perror 这个函数打印失败的原因。
struct stat结构体:

struct stat {
	dev_t st_dev; // 包含这个文件的设备id
	ino_t st_ino; // inode编号
	mode_t st_mode; // 访问权限
	nlink_t st_link; // 硬链接数量
	uid_t st_uid; // 用户id
	gid_t st_gid; // 组id
	dev_t st_rdev; // 设备id
	off_t st_size; // 文件占用的字节数
	blksize_t st_blksize; // 文件系统块大小
	blkcnt_t st_blocks; // 文件占用了几个block
	time_t st_atime; // 最后访问时间
	time_t st_mtime; // 最后内容修改时间
	time_t st_ctime; // 最后状态修改时间
}

猜你喜欢

转载自blog.csdn.net/u012086173/article/details/86500613