This is useful for filesystems where d_type is always DT_UNKNOWN,
for example reiserfs, jffs2 and ubifs. In this case use the
fstatat() function.
DIR *dir;
struct dirent *d;
char *str, pathname[PATH_MAX];
+ struct stat buf;
+ int ret;
if (subpath == NULL)
strncpy(pathname, basepath, sizeof(pathname));
return str;
}
break;
+ case DT_UNKNOWN:
+ /*
+ * If there is no d_type support use fstatat()
+ * to check if d_name is directory
+ * Let the code fall through
+ */
+ ret = fstatat(dirfd(dir), d->d_name, &buf, 0);
+ if (ret < 0)
+ continue;
+ if ((buf.st_mode & S_IFDIR) == 0)
+ continue;
case DT_DIR:
if (subpath == NULL)
strncpy(pathname, d->d_name, sizeof(pathname));