From e0a364786c001a6aa3b2ff5b5a2ed1cb31a0b391 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 31 Dec 2014 19:25:45 +0100 Subject: [PATCH] Further cleanups to dir_list_new --- libretro-sdk/file/dir_list.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/libretro-sdk/file/dir_list.c b/libretro-sdk/file/dir_list.c index e90a8926f9..2c987fef61 100644 --- a/libretro-sdk/file/dir_list.c +++ b/libretro-sdk/file/dir_list.c @@ -89,6 +89,7 @@ void dir_list_free(struct string_list *list) string_list_free(list); } +#ifndef _WIN32 static bool dirent_is_directory(const char *path, const struct dirent *entry) { @@ -105,6 +106,7 @@ static bool dirent_is_directory(const char *path, return path_is_directory(path); #endif } +#endif /* Return values: * -1 - error @@ -163,21 +165,28 @@ static int parse_dir_entry(const char *name, char *file_path, struct string_list *dir_list_new(const char *dir, const char *ext, bool include_dirs) { -#ifdef _WIN32 char path_buf[PATH_MAX]; + struct string_list *ext_list, *list; +#ifdef _WIN32 WIN32_FIND_DATA ffd; - struct string_list *ext_list = NULL; HANDLE hFind = INVALID_HANDLE_VALUE; - struct string_list *list = string_list_new(); +#else + DIR *directory = NULL; + const struct dirent *entry = NULL; +#endif - if (!list) + ext_list = NULL; + (void)path_buf; + + if (!(list = string_list_new())) return NULL; - snprintf(path_buf, sizeof(path_buf), "%s\\*", dir); - if (ext) ext_list = string_split(ext, "|"); +#ifdef _WIN32 + snprintf(path_buf, sizeof(path_buf), "%s\\*", dir); + hFind = FindFirstFile(path_buf, &ffd); if (hFind == INVALID_HANDLE_VALUE) goto error; @@ -210,17 +219,6 @@ error: if (hFind != INVALID_HANDLE_VALUE) FindClose(hFind); #else - DIR *directory = NULL; - const struct dirent *entry = NULL; - struct string_list *ext_list = NULL; - struct string_list *list = string_list_new(); - - if (!list) - return NULL; - - if (ext) - ext_list = string_split(ext, "|"); - directory = opendir(dir); if (!directory) goto error;