This commit is contained in:
twinaphex 2015-08-31 11:03:00 +02:00
parent 9895cd6b21
commit 27a8022af1

View File

@ -202,6 +202,19 @@ static int parse_dir_entry(const char *name, char *file_path,
return 0; return 0;
} }
#if defined(_WIN32)
#define dirent_closedir(directory) \
if (directory != INVALID_HANDLE_VALUE) \
FindClose(directory)
#elif defined(VITA)
#define dirent_closedir(directory) sceIoDclose(directory)
#else
#define dirent_closedir(directory) \
if (directory) \
closedir(directory)
#endif
/** /**
* dir_list_new: * dir_list_new:
* @dir : directory path. * @dir : directory path.
@ -220,7 +233,7 @@ struct string_list *dir_list_new(const char *dir,
#if defined(_WIN32) #if defined(_WIN32)
char path_buf[PATH_MAX_LENGTH]; char path_buf[PATH_MAX_LENGTH];
WIN32_FIND_DATA entry; WIN32_FIND_DATA entry;
HANDLE hFind = INVALID_HANDLE_VALUE; HANDLE directory = INVALID_HANDLE_VALUE;
#elif defined(VITA) #elif defined(VITA)
SceUID directory; SceUID directory;
SceIoDirent entry; SceIoDirent entry;
@ -240,11 +253,11 @@ struct string_list *dir_list_new(const char *dir,
#ifdef _WIN32 #ifdef _WIN32
snprintf(path_buf, sizeof(path_buf), "%s\\*", dir); snprintf(path_buf, sizeof(path_buf), "%s\\*", dir);
hFind = FindFirstFile(path_buf, &entry); directory = FindFirstFile(path_buf, &entry);
if (hFind == INVALID_HANDLE_VALUE) if (directory == INVALID_HANDLE_VALUE)
goto error; goto error;
while (FindNextFile(hFind, &entry) != 0) while (FindNextFile(directory, &entry) != 0)
#elif defined(VITA) #elif defined(VITA)
directory = sceIoDopen(dir); directory = sceIoDopen(dir);
if (directory < 0) if (directory < 0)
@ -285,28 +298,13 @@ struct string_list *dir_list_new(const char *dir,
continue; continue;
} }
#ifdef _WIN32 dirent_closedir(directory);
FindClose(hFind);
#elif defined(VITA)
sceIoDclose(directory);
#else
if (directory)
closedir(directory);
#endif
string_list_free(ext_list); string_list_free(ext_list);
return list; return list;
error: error:
#if defined(_WIN32) dirent_closedir(directory);
if (hFind != INVALID_HANDLE_VALUE)
FindClose(hFind);
#elif defined(VITA)
sceIoDclose(directory);
#else
if (directory)
closedir(directory);
#endif
string_list_free(list); string_list_free(list);
string_list_free(ext_list); string_list_free(ext_list);