设为首页收藏本站 |天气与日历| 2025-04-20 星期日 05:54:00 乙巳(蛇)年 三月廿三 卯时 谷雨
     
切换到窄版

私人站点

 找回密码
 立即注册
搜索
查看: 124|回复: 0

stat 获取文件状态

[复制链接]

954

主题

954

帖子

3875

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3875
发表于 2021-12-7 13:02:36 | 显示全部楼层 |阅读模式
#include <sys/types.h>
#include <sys/stat.h>
int stat(constchar *path, structstat *buf);
功能:获取文件状态信息
参数:
path:文件名
buf:保存文件信息的结构体
返回值:
成功:0
失败-1

[Plain Text] 纯文本查看 复制代码
struct stat {
        dev_t         st_dev;         //文件的设备编号
        ino_t         st_ino;          //节点
        mode_t        st_mode;   //文件的类型和存取的权限
        nlink_t       st_nlink;     //连到该文件的硬连接数目,刚建立的文件值为1
        uid_t         st_uid;         //用户ID
        gid_t         st_gid;         //组ID
        dev_t         st_rdev;      //(设备类型)若此文件为设备文件,则为其设备编号
        off_t         st_size;        //文件字节数(文件大小)
        unsigned long st_blksize;   //块大小(文件系统的I/O 缓冲区大小)
        unsigned long st_blocks;    //块数
        time_t        st_atime;     //最后一次访问时间
        time_t        st_mtime;    //最后一次修改时间
        time_t        st_ctime;     //最后一次改变时间(指属性)
};
[C] 纯文本查看 复制代码
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
int main(int argc, char **args)
{
        if (argc < 2)
                return 0;
        struct stat st = { 0 };
        stat(args[1], &st);
        int size = st.st_size;//得到结构体中的成员变量
        printf("%d\n", size);
        return 0;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|编程站点 ( 冀ICP备2023028127号-2 )|友链申请|

GMT+8, 2025-4-20 05:54 , Processed in 0.085535 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表