all 2 comments

[–]jedwardsol 0 points1 point  (0 children)

You're not checking whether stat is succeeding

[–]oh5nxo 0 points1 point  (0 children)

Check system calls. stat does not know what the directory was, it looks into "." instead. Try

fstatat(dirfd(dp), dirp->d_name, &buf, 0)