第四节 stat函数和目录索引使用

本文主要介绍Linux系统编程中,如何使用stat函数获取文件属性,并探讨opendir、closedir和readdir进行目录操作的方法,是个人学习笔记。
摘要由CSDN通过智能技术生成

stat:功能:获取文件的属性

    #include <sys/types.h>
    #include <sys/stat.h>
    #include <unistd.h>

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

    path:你要查看的文件的位置
    buf:存放文件属性的结构体,结构体解释如下:
    返回值:成功返回0,错误返回-1

    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 */ 用户ID
               gid_t     st_gid;     /* group ID of owner */    组ID
               dev_t     st_rdev;    /* device ID (if special file) */特殊设备ID
               off_t     st_size;    /* total size, in bytes */ 文件大小,特殊文件判断不了
            
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值