From b499206a003589e2414dfdcb7f813bb46afd6fbc Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 23 Nov 2012 23:26:31 +0100 Subject: [PATCH] Handle DT_UNKNOWN special case. Some filesystems return DT_UNKNOWN in dirent. Fallback to stat(). --- file_path.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/file_path.c b/file_path.c index 2b54dab2e3..45c58ed419 100644 --- a/file_path.c +++ b/file_path.c @@ -268,6 +268,22 @@ error: return NULL; } #else +static bool dirent_is_directory(const char *path, const struct dirent *entry) +{ +#if defined(PSP) + return (entry->d_stat.st_attr & FIO_SO_IFDIR) == FIO_SO_IFDIR; +#elif defined(DT_DIR) + if (entry->d_type == DT_DIR) + return true; + else if (entry->d_type == DT_UNKNOWN) // This can happen on certain file systems. + return path_is_directory(path); + else + return false; +#else // dirent struct doesn't have d_type, do it the slow way ... + return path_is_directory(path); +#endif +} + struct string_list *dir_list_new(const char *dir, const char *ext, bool include_dirs) { struct string_list *list = string_list_new(); @@ -289,12 +305,11 @@ struct string_list *dir_list_new(const char *dir, const char *ext, bool include_ { const char *name = entry->d_name; const char *file_ext = path_get_extension(name); -#ifdef PSP - bool is_dir = ((entry->d_stat.st_attr & FIO_SO_IFDIR) == FIO_SO_IFDIR); -#else - bool is_dir = entry->d_type == DT_DIR; -#endif + char file_path[PATH_MAX]; + snprintf(file_path, sizeof(file_path), "%s/%s", dir, name); + + bool is_dir = dirent_is_directory(file_path, entry); if (!include_dirs && is_dir) continue; @@ -304,9 +319,6 @@ struct string_list *dir_list_new(const char *dir, const char *ext, bool include_ if (!is_dir && ext_list && !string_list_find_elem_prefix(ext_list, ".", file_ext)) continue; - char file_path[PATH_MAX]; - snprintf(file_path, sizeof(file_path), "%s/%s", dir, name); - union string_list_elem_attr attr; attr.b = is_dir;