Recently I had some pretty unexpected results from a piece of code I wrote quite a while ago, and never had any issues with.
I ran my program on a brand new CentOS 7 installation, and the results weren’t at all what I was used to!
Consider the following code (abridged and simplified):
After a bit of head scratching, and a few debug statements, I found that when using readdir(3) on XFS, dirent->d_type is always 0! No matter what type of file it is.
This means that line #25 can never be true.
To be fair though, the manpage states that POSIX only mandates dirent->d_name.
So to be absolutely sure your directory traversal code is more portable, make use of stat(2) and the S_ISDIR() macro!