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
struct stat结构体的详解和用法的更多相关文章
- 结构体指针,C语言结构体指针详解
结构体指针,可细分为指向结构体变量的指针和指向结构体数组的指针. 指向结构体变量的指针 前面我们通过“结构体变量名.成员名”的方式引用结构体变量中的成员,除了这种方法之外还可以使用指针. 前面讲过,& ...
- inode结构体成员详解
概述:inode译成中文就是索引节点,它用来存放档案及目录的基本信息,包含时间.档名.使用者及群组等.inode分为内存中的inode和文件系统中的inode,为了避免混淆,我们称前者为VFS ino ...
- Solidity的自定义结构体深入详解
一.结构体定义 结构体,Solidity中的自定义类型.我们可以使用Solidity的关键字struct来进行自定义.结构体内可以包含字符串,整型等基本数据类型,以及数组,映射,结构体等复杂类型.数组 ...
- IPv4地址结构体sockaddr_in详解
sockaddr_in结构体定义 struct sockaddr_in { sa_family_t sin_family; //地址族(Address Family) uint16_t sin_por ...
- struct socket结构体详解
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://weiguozhihui.blog.51cto.com/3060615/15852 ...
- Scala 深入浅出实战经典 第53讲:Scala中结构类型实战详解
王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-64讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 ...
- struct ifreq结构体与ip,子网掩码,网关等信息
总结一下,今天学习的关于通过socket,ioctl来获得ip,netmask等信息,其中很多内容参照了很多网上的信息,我会一一列出的 我用的这个函数,就是下面这个函数,其中的有一些全局变量,很好懂, ...
- Golang面向对象编程-struct(结构体)
Golang面向对象编程-struct(结构体) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是面向对象编程 面向对象编程(Object Oriented Program ...
- struct timeval结构体 以及 gettimeofday()函数(转)
struct timeval结构体 转载地址:http://blog.chinaunix.net/uid-20548989-id-2533161.html 该结构体是Linux系统中定义,struct ...
随机推荐
- C++ 学习的网站
C++入门教程: http://see.xidian.edu.cn/cpp/biancheng/cpp/rumen/
- 【bzoj3343】教主的魔法 分块
[bzoj3343]教主的魔法 2014年4月26日8092 Description 教主最近学会了一种神奇的魔法,能够使人长高.于是他准备演示给XMYZ信息组每个英雄看.于是N个英雄们又一次聚集在了 ...
- Codeforces Codeforces Round #316 (Div. 2) C. Replacement set
C. Replacement Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/proble ...
- [HTTP那些事] JSON数据
随着Android的发展,各路大神的贡献,我们可用的轮子越来越多.比如HTTP请求框架,有自家的Volley,Square的okhttp, async-http-lib, 还有聚合版的xUtils以及 ...
- HealthKit开发教程之HealthKit的复合数据
HealthKit开发教程之HealthKit的复合数据 复合数据就是复合单位和值构成的数据.所谓复合单位就是由单位进行乘法.除法等得到的单位,如m/s.lb·ft等就是复合单位.本节将针对这些复合数 ...
- C Golden gun的巧克力
Time Limit:1000MS Memory Limit:65535K 题型: 编程题 语言: 无限制 描述 众所周知,13级有尊大神Golden gun,人称根叔,简称金枪!众立志进校队的 ...
- Codeforces Round #329 (Div. 2)
推迟了15分钟开始,B卡住不会,最后弃疗,rating只涨一分... 水(暴力枚举) A - 2Char /******************************************** ...
- 逆序数2 HDOJ 1394 Minimum Inversion Number
题目传送门 /* 求逆序数的四种方法 */ /* 1. O(n^2) 暴力+递推 法:如果求出第一种情况的逆序列,其他的可以通过递推来搞出来,一开始是t[1],t[2],t[3]....t[N] 它的 ...
- datetime与smalldatetime之间的区别
1.一直以为smalldatetime和datetime的差别只是在于时间范围: smalldatetime的有效时间范围1900/1/1~2079/6/6datetime的有效时间范围1753/1/ ...
- LA 4080 (多源最短路径+边修改+最短路径树)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32266 题目大意:①先求任意两点间的最短路径累加和,其中不连通的边 ...
