加入收藏 | 设为首页 | 会员中心 | 我要投稿 佛山站长网 (https://www.0757zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

linux系统编程之文件与I/O(四) 文件的属性

发布时间:2013-10-12 12:21:06 所属栏目:Linux 来源:站长网
导读:一、读取文件元数据 int stat(const char *path, struct stat *buf); int fstat(int fd, struct stat *buf); int lstat(const char *path, struct stat *buf);
一、读取文件元数据

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

int fstat(int fd, struct stat *buf);

int lstat(const char *path, struct stat *buf);

stat() stats the file pointed to by path and fills in buf.

lstat()  is  identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the file that it refers to.

fstat() is identical to stat(), except that the file to be stat-ed is specified by the file descriptor fd.

二、stat结构体

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 */

};

(编辑:佛山站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读