看了个关于stat的帖子~~
原来还米用过滴~~

在网上查了资料~~

自己调试了下~~
原来stat()是这么好用哇~~

以下是转载别人的blog~~

函数都是获取文件(普通文件,目录,管道,socket,字符,块()的属性。

函数原型
#include <sys/stat.h>
int stat(const char *restrict pathname, struct stat *restrict buf);
提供文件名字,获取文件对应属性。
int fstat(int filedes, struct stat *buf);
通过文件描述符获取文件对应的属性。
int lstat(const char *restrict pathname, struct stat *restrict buf);
连接文件描述命,获取文件属性。
struct stat {
        mode_t     st_mode;       //文件对应的模式,文件,目录等
        ino_t      st_ino;       //inode节点号
        dev_t      st_dev;        //设备号码
        dev_t      st_rdev;       //特殊设备号码
        nlink_t    st_nlink;      //文件的连接数
        uid_t      st_uid;        //文件所有者
        gid_t      st_gid;        //文件所有者对应的组
        off_t      st_size;       //普通文件,对应的文件字节数
        time_t     st_atime;      //文件最后被访问的时间
        time_t     st_mtime;      //文件内容最后被修改的时间
        time_t     st_ctime;      //文件状态改变时间
        blksize_t st_blksize;    //文件内容对应的块大小
        blkcnt_t   st_blocks;     //伟建内容对应的块数量
      };
这是自己的调试代码~~
#include <iostream>

#include <sys/stat.h>

using namespace std;
int main(){
   struct stat buf;
    if(stat("d:/abc.txt",&buf)!=-1)
      std::cout<<ctime(&(buf.st_atime))<<std::endl;
      std::cin.get();

      return 0;   
}
以后有了新知识都会写的~~给自己加深记忆~~!!

发表于 @ 2008年11月30日