首页 新闻 赞助 找找看

struct stat 的用法

0
悬赏园豆:5 [已关闭问题] 关闭于 2012-04-25 15:04

有一个关于文件目录的函数如下:

1 bool isDirectory( const std::string& path ) 
2 {
3 struct stat s;
4 int result = stat( path.c_str(), &s );//gkm:提供文件名字,获取文件对应属性,并保存在s所指的结构体内
5 bool actualDirectory = (result >= 0) && (s.st_mode & S_IFDIR);
6 
7 return actualDirectory;
8 }

请问第5行里(s.st_mode & S_IFDIR)的意义是什么,第5行的意义是什么?

c++
NLP新手的主页 NLP新手 | 菜鸟二级 | 园豆:204
提问于:2012-04-24 20:04
< >
分享
所有回答(2)
0

stat的结构是什么?

artwl | 园豆:16736 (专家六级) | 2012-04-24 20:13
              struct stat {
                  dev_t         st_dev;      /* device */
                  ino_t         st_ino;      /* inode */
                  mode_t        st_mode;     /* protection */
                  nlink_t       st_nlink;    /* number of hard links */
                  uid_t         st_uid;      /* user ID of owner */
                  gid_t         st_gid;      /* group ID of owner */
                  dev_t         st_rdev;     /* device type (if inode device) */
                  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 change */
              };
支持(0) 反对(0) NLP新手 | 园豆:204 (菜鸟二级) | 2012-04-24 20:15

@kevinGao: 还是有很多地方不全,没法判断啊

支持(0) 反对(0) artwl | 园豆:16736 (专家六级) | 2012-04-24 20:50
0

(s.st_mode & S_IFDIR)的具体细节我还不清楚,它的意义大体是判断上面的path是个文件名还是个目录名

NLP新手 | 园豆:204 (菜鸟二级) | 2012-04-25 15:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册