struct stat结构体的详解和用法
- //! 需要包含de头文件
- #include <sys/types.h>
- #include <sys/stat.h>
S_ISLNK(st_mode):是否是一个连接.
S_ISREG(st_mode):是否是一个常规文件.
S_ISDIR(st_mode):是否是一个目录
S_ISCHR(st_mode):是否是一个字符设备.
S_ISBLK(st_mode):是否是一个块设备
S_ISFIFO(st_mode):是否 是一个FIFO文件.
S_ISSOCK(st_mode):是否是一个SOCKET文件
- int stat(const char *filename, struct stat *buf); //! prototype,原型
- struct stat
- {
- dev_t st_dev; /* ID of device containing file -文件所在设备的ID*/
- ino_t st_ino; /* inode number -inode节点号*/
- mode_t st_mode; /* protection -保护模式?*/
- nlink_t st_nlink; /* number of hard links -链向此文件的连接数(硬连接)*/
- uid_t st_uid; /* user ID of owner -user id*/
- gid_t st_gid; /* group ID of owner - group id*/
- dev_t st_rdev; /* device ID (if special file) -设备号,针对设备文件*/
- off_t st_size; /* total size, in bytes -文件大小,字节为单位*/
- blksize_t st_blksize; /* blocksize for filesystem I/O -系统块的大小*/
- blkcnt_t st_blocks; /* number of 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 - */
- };
- #include <iostream>
- #include <ctime>
- #include <sys/types.h>
- #include <sys/stat.h>
- using namespace std;
- int
- main ()
- {
- struct stat buf;
- int result;
- result = stat ("./Makefile", &buf);
- if (result != 0)
- {
- perror ("Failed ^_^");
- }
- else
- {
- //! 文件的大小,字节为单位
- cout << "size of the file in bytes: " << buf.st_size << endl;
- //! 文件创建的时间
- cout << "time of creation of the file: " << ctime (&buf.st_ctime) <<
- endl;
- //! 最近一次修改的时间
- cout << "time of last modification of the file: " <<
- ctime (&buf.st_mtime) << endl;
- //! 最近一次访问的时间
- cout << "time of last access of the file: " << ctime (&buf.st_atime)
- << endl;
- }
- return 0;
- }
- $ ./test
- size of the file in bytes: 36
- time of creation of the file: Sun May 24 18:38:10 2009
- time of last modification of the file: Sun May 24 18:38:10 2009
- time of last access of the file: Sun May 24 18:38:13 2009
转载于:https://www.cnblogs.com/wxmdevelop/p/4649495.html
struct stat结构体的详解和用法相关推荐
- 结构体+联合体 详解
文章目录 一.结构体 1.结构体变量 2.特殊声明 3.结构体的引用 1.嵌套调用 2.自引用 三.结构体的初始化 四.结构体的内存对齐 1.用法 2.练习题 3.修改对齐数 五.位段 1.用法 2. ...
- C语言指针结构体详解,结构体指针,C语言结构体指针详解
结构体指针,可细分为指向结构体变量的指针和指向结构体数组的指针. 指向结构体变量的指针 前面我们通过"结构体变量名.成员名"的方式引用结构体变量中的成员,除了这种方法之外还可以使用 ...
- c语言结构体指针详解,结构体指针,C语言结构体指针详解
结构体指针,可细分为指向结构体变量的指针和指向结构体数组的指针. 指向结构体变量的指针 前面我们通过"结构体变量名.成员名"的方式引用结构体变量中的成员,除了这种方法之外还可以使用 ...
- C语言——结构体(入门详解)
结构体 文章目录 结构体 1.结构体的引出 2.结构体与结构体变量的关系示意图 3.**快速入门面向对象的方式(struct)解决养猫问题** 4.结构体和结构体变量的区别和联系 5.结构体变量在内存 ...
- C语言结构体对齐详解
文章目录 一.C语言结构体对齐大小快速判断 二.反汇编角度看结构体 三.总结 一.C语言结构体对齐大小快速判断 在C语言中定义一个结构体,里面具体占用多少个字节呢,先举一个例子,如下: #includ ...
- c语言 一个函数返回结构体指针,详解C语言结构体中的函数指针
结构体是由一系列具有相同类型或不同类型的数据构成的数据集合.所以,标准C中的结构体是不允许包含成员函数的,当然C++中的结构体对此进行了扩展.那么,我们在C语言的结构体中,只能通过定义函数指针的方式, ...
- 【C语言】结构体定义 typedef struct 用法详解和用法小结
结构体定义 typedef struct 用法详解和用法小结 文章目录 结构体定义 typedef struct 用法详解和用法小结 0. 前言 1. 首先:在C中定义一个结构体类型要用typedef ...
- struct sk_buff结构体详解
struct sk_buff是linux网络系统中的核心结构体,linux网络中的所有数据包的封装以及解封装都是在这个结构体的基础上进行. 1 2 3 4 5 6 7 8 9 10 11 12 13 ...
- linux sock结构体,struct socket结构体详解
在内核中为什么要有struct socket结构体呢? struct socket结构体的作用是什么? 下面这个图,我觉得可以回答以上两个问题. 由这个图可知,内核中的进程可以通过使用struct ...
最新文章
- AppData::create pipe(2) failed: Too many open file
- printf 规定数据输出方式
- Docker - 导出导入容器
- linux jmeter 内存,JMeter-Linux内存不足
- lucene造成磁盘空间不足的问题
- 软件测试52讲-安全第一:渗透测试
- ASP.NET Core 中间件Diagnostics使用 异常和错误信息
- 31线性空间05——列空间和零空间、维数
- BIND9源码分析奠基
- Android Dialog的简单说明
- iostate知识要点
- 70多套java必练项目,适合小白上手!
- oracle学习札记95
- WinZip for Mac注册版
- WINDOWS2008server安全策略设置
- Bootstrap系列之面包屑导航(Breadcrumb)
- peopleSoft常见错误诊断
- Power BI中文版
- 如何在Commander One中显示隐藏文件?
- linux网卡的配置文件是双引号,Linux修改网卡ens33为eth0以及centos7下修改动态IP为静态IP地址...
热门文章
- VS2012代码提示快捷键
- 阿里云Centos 解决挖矿程序:kdevtmpfsi--服务器CPU占用高、内存占用高
- SpringBoot2.x 不反回空值属性
- 由于找不到PBSYS90.dll,无法继续执行代码。重新安装程序可能会解决此问题!
- 面试常碰到++p/p--问题到底结果是什么?
- iloc loc 区别
- Imagination发布四款RISC-V CPU
- 2021年大数据ELK(二十二):采集Apache Web服务器日志
- Androidx FloatingActionButton 中间图片颜色值修改
- Android Studio 引入aar文件