The following line should be testing whether the current file is a directory or not:
if ((stbuf.st_mode & S_IFMT) == S_IFDIR)
//file is a directory.
where stbuf
is of type
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 */
};
and S_IFMT
and S_IFDIR
are defined as
#define S_IFMT 0160000 /* type of file: */
#define S_IFDIR 0040000 /* directory */
I can't understand how the statement given above will work? Please can anyone explain logic behind it.
Thanks.