以下行应该测试当前文件是否为目录:
if ((stbuf.st_mode & S_IFMT) == S_IFDIR)
//file is a directory.
stbuf
类型 在哪里
struct stat /* inode information returned by stat */
{
dev_t st_dev; /* device of inode */
ino_t st_ino; /* inode number */
short st_mode; /* mode bits */
short st_nlink; /* number of links to file */
short st_uid; /* owners user id */
short st_gid; /* owners group id */
dev_t st_rdev; /* for special files */
off_t st_size; /* file size in characters */
time_t st_atime; /* time last accessed */
time_t st_mtime; /* time last modified */
time_t st_ctime; /* time originally created */
};
和定义 S_IFMT
为S_IFDIR
#define S_IFMT 0160000 /* type of file: */
#define S_IFDIR 0040000 /* directory */
我不明白上面给出的声明将如何工作?请任何人解释其背后的逻辑。
谢谢。