Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4183735
  • 博文数量: 776
  • 博客积分: 13014
  • 博客等级: 上将
  • 技术积分: 10391
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-22 17:00
文章分类

全部博文(776)

文章存档

2015年(55)

2014年(43)

2013年(147)

2012年(20)

2011年(82)

2010年(429)

分类: LINUX

2010-12-24 14:51:28

简介
  1. //! 需要包含de头文件

  2. #include <sys/types.h>
  3. #include <sys/stat.h>

  4. int stat(const char *filename, struct stat *buf); //! prototype,原型


  5. struct stat
  6. {
  7.     dev_t st_dev; /* ID of device containing file -文件所在设备的ID*/
  8.     ino_t st_ino; /* inode number -inode节点号*/
  9.     mode_t st_mode; /* protection -保护模式?*/
  10.     nlink_t st_nlink; /* number of hard links -链向此文件的连接数(硬连接)*/
  11.     uid_t st_uid; /* user ID of owner -user id*/
  12.     gid_t st_gid; /* group ID of owner - group id*/
  13.     dev_t st_rdev; /* device ID (if special file) -设备号,针对设备文件*/
  14.     off_t st_size; /* total size, in bytes -文件大小,字节为单位*/
  15.     blksize_t st_blksize; /* blocksize for filesystem I/O -系统块的大小*/
  16.     blkcnt_t st_blocks; /* number of blocks allocated -文件所占块数*/
  17.     time_t st_atime; /* time of last access -最近存取时间*/
  18.     time_t st_mtime; /* time of last modification -最近修改时间*/
  19.     time_t st_ctime; /* time of last status change - */
  20. };
使用范例
#include
#include
#include
#include
 
using namespace std;
 
int main ()
{
    struct stat buf;
    int result;
    result = stat ( "./stat.c", &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;
}
阅读(1625) | 评论(0) | 转发(0) |
0

上一篇:在cygwin下以root登录方法

下一篇:fstat.c

给主人留下些什么吧!~~