Linux 下的 stat 函数

首先了解 struct stat 这个机构体

struct stat 
{
    short st_dev;               //普通文件存在存储器设备号
    short st_ino;               //文件索引号
    short st_mode;              //文件类型和模式
    short st_nlink;             //引用计数: 文件名字总数,因为link可以取别名
    int   st_uid;               //文件使用者的UID
    int   st_gid;               //文件所属组的GID
    short st_rdev;              //特殊文件设备号
    long  st_size;              //文件大小
    long  st_atime;             //最近访问时间
    long  st_mtime;             //最近修改时间
    long  st_ctime;             //最近属性更改时间
    blksize_t st_blksize;       //写数据块建议值
};

函数原型:
int stat(const char *path, struct stat *buf);
返回值:
0 成功
NULL 失败
参数:
path 文件名
buf 指向struct stat 类型的指针
作用:
将 path 文件的属性写入 struct stat *buf 指向的内存
通过访问 buf 指向的内存获取文件信息

猜你喜欢

转载自blog.csdn.net/qq_41985711/article/details/81456108
今日推荐