1. //! 需要包含de头文件
  2. #include <sys/types.h>
  3. #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文件 

  1. int stat(const char *filename, struct stat *buf); //! prototype,原型
  2. struct stat
  3. {
  4. dev_t       st_dev;     /* ID of device containing file -文件所在设备的ID*/
  5. ino_t       st_ino;     /* inode number -inode节点号*/
  6. mode_t      st_mode;    /* protection -保护模式?*/
  7. nlink_t     st_nlink;   /* number of hard links -链向此文件的连接数(硬连接)*/
  8. uid_t       st_uid;     /* user ID of owner -user id*/
  9. gid_t       st_gid;     /* group ID of owner - group id*/
  10. dev_t       st_rdev;    /* device ID (if special file) -设备号,针对设备文件*/
  11. off_t       st_size;    /* total size, in bytes -文件大小,字节为单位*/
  12. blksize_t   st_blksize; /* blocksize for filesystem I/O -系统块的大小*/
  13. blkcnt_t    st_blocks;  /* number of blocks allocated -文件所占块数*/
  14. time_t      st_atime;   /* time of last access -最近存取时间*/
  15. time_t      st_mtime;   /* time of last modification -最近修改时间*/
  16. time_t      st_ctime;   /* time of last status change - */
  17. };

  1. #include <iostream>
  2. #include <ctime>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. using namespace std;
  6. int
  7. main ()
  8. {
  9. struct stat buf;
  10. int result;
  11. result = stat ("./Makefile", &buf);
  12. if (result != 0)
  13. {
  14. perror ("Failed ^_^");
  15. }
  16. else
  17. {
  18. //! 文件的大小,字节为单位
  19. cout << "size of the file in bytes: " << buf.st_size << endl;
  20. //! 文件创建的时间
  21. cout << "time of creation of the file: " << ctime (&buf.st_ctime) <<
  22. endl;
  23. //! 最近一次修改的时间
  24. cout << "time of last modification of the file: " <<
  25. ctime (&buf.st_mtime) << endl;
  26. //! 最近一次访问的时间
  27. cout << "time of last access of the file: " << ctime (&buf.st_atime)
  28. << endl;
  29. }
  30. return 0;
  31. }

  1. $ ./test
  2. size of the file in bytes: 36
  3. time of creation of the file: Sun May 24 18:38:10 2009
  4. time of last modification of the file: Sun May 24 18:38:10 2009
  5. time of last access of the file: Sun May 24 18:38:13 2009

struct stat结构体的详解和用法的更多相关文章

  1. 结构体指针,C语言结构体指针详解

    结构体指针,可细分为指向结构体变量的指针和指向结构体数组的指针. 指向结构体变量的指针 前面我们通过“结构体变量名.成员名”的方式引用结构体变量中的成员,除了这种方法之外还可以使用指针. 前面讲过,& ...

  2. inode结构体成员详解

    概述:inode译成中文就是索引节点,它用来存放档案及目录的基本信息,包含时间.档名.使用者及群组等.inode分为内存中的inode和文件系统中的inode,为了避免混淆,我们称前者为VFS ino ...

  3. Solidity的自定义结构体深入详解

    一.结构体定义 结构体,Solidity中的自定义类型.我们可以使用Solidity的关键字struct来进行自定义.结构体内可以包含字符串,整型等基本数据类型,以及数组,映射,结构体等复杂类型.数组 ...

  4. IPv4地址结构体sockaddr_in详解

    sockaddr_in结构体定义 struct sockaddr_in { sa_family_t sin_family; //地址族(Address Family) uint16_t sin_por ...

  5. struct socket结构体详解

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://weiguozhihui.blog.51cto.com/3060615/15852 ...

  6. Scala 深入浅出实战经典 第53讲:Scala中结构类型实战详解

    王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-64讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 ...

  7. struct ifreq结构体与ip,子网掩码,网关等信息

    总结一下,今天学习的关于通过socket,ioctl来获得ip,netmask等信息,其中很多内容参照了很多网上的信息,我会一一列出的 我用的这个函数,就是下面这个函数,其中的有一些全局变量,很好懂, ...

  8. Golang面向对象编程-struct(结构体)

    Golang面向对象编程-struct(结构体) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是面向对象编程 面向对象编程(Object Oriented Program ...

  9. struct timeval结构体 以及 gettimeofday()函数(转)

    struct timeval结构体 转载地址:http://blog.chinaunix.net/uid-20548989-id-2533161.html 该结构体是Linux系统中定义,struct ...

随机推荐

  1. Office Word 2013发布带数学公式的博客

    今日在自学冈萨雷斯的<数字图像处理>一书,想做笔记来记录,并分享一些MATLAB代码,又加上刚刚注册博客园的账户,便想着如何能够较为方便的来书写博客.本文主要涉及到的问题有: 如何用wor ...

  2. loj 1011(状态压缩+记忆化搜索)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25837 思路:状态压缩+记忆化搜索. #include<io ...

  3. 013_VM+WinDbg安装

    预计平均三天一课,录制过程中,大纲会实时更新(更改) 主讲:郁金香灬老师  QQ150330575 开发环境:VC6,VS2003,VS2008 www.yjxsoft.net www.yjxsoft ...

  4. 【框架】RefreshListView下拉刷新

    布局: <com.example.administrator.d30_myrefreshlistview.RefreshListView android:id="@+id/refres ...

  5. cocos2d 消息映射

    alayer #include "ALayer.hpp" ALayer::ALayer(void) { } ALayer::~ALayer(void) { } bool ALaye ...

  6. Android WebView常见问题解决方案汇总

    问题目录: 1.为WebView自定义错误显示界面: 2.WebView cookies清理 3.清理cache 和历史记录 4.判断WebView是否已经滚动到页面底端 5.URL拦截 6.处理We ...

  7. 《菊与刀》--[美]鲁思·本尼迪克特(Ruth Benedict)

    <菊与刀>这本书实在是好看. 下面是一些书摘: * 由在美国曾经全力以赴与之战斗的敌人中,日本人的脾气是最琢磨不透的. * “菊”本是日本皇家家微,“刀”是武家文化的象征. * 日本人的格 ...

  8. sqlserver行列转换

    sqlserver行转列 --创建行转列表及插入数据 create table tb_RowConvertToColumn ( username ) null, course ) null, scor ...

  9. linux下安装uuid库

    1.linux 下安装UUID库 1.1)ubuntu下安装uuid链接库 sudo apt-get install uuid-dev 1.2)CentOS yum install libuuid-d ...

  10. Java虚拟机(JVM)中的内存设置详解

    在一些规模稍大的应用中,Java虚拟机(JVM)的内存设置尤为重要,想在项目中取得好的效率,GC(垃圾回收)的设置是第一步. PermGen space:全称是Permanent Generation ...