From b03347dc487b156e4d819e318426ad0206f7d651 Mon Sep 17 00:00:00 2001 From: zeromus Date: Fri, 22 Apr 2016 01:38:26 +0000 Subject: [PATCH] retro_dirent and retro_stat tidy and bugfixes: windows retro_dir would have missed the first entry; retro_stat wasn't extern "C"'d; retro_dirent_is_dir didn't need a path argument (path can always be gotten from RDIR in a trivial operation) --- desmume/src/libretro-common/file/retro_dirent.c | 12 ++++++++++-- desmume/src/libretro-common/include/retro_dirent.h | 3 +-- desmume/src/libretro-common/include/retro_stat.h | 8 ++++++++ desmume/src/libretro-common/lists/dir_list.c | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/desmume/src/libretro-common/file/retro_dirent.c b/desmume/src/libretro-common/file/retro_dirent.c index 82dd2672b..0276543b8 100644 --- a/desmume/src/libretro-common/file/retro_dirent.c +++ b/desmume/src/libretro-common/file/retro_dirent.c @@ -64,6 +64,7 @@ struct RDIR #if defined(_WIN32) WIN32_FIND_DATA entry; HANDLE directory; + bool next; #elif defined(VITA) || defined(PSP) SceUID directory; SceIoDirent entry; @@ -118,7 +119,12 @@ bool retro_dirent_error(struct RDIR *rdir) int retro_readdir(struct RDIR *rdir) { #if defined(_WIN32) - return (FindNextFile(rdir->directory, &rdir->entry) != 0); + if(rdir->next) + return (FindNextFile(rdir->directory, &rdir->entry) != 0); + else { + rdir->next = true; + return (rdir->directory != INVALID_HANDLE_VALUE); + } #elif defined(VITA) || defined(PSP) return (sceIoDread(rdir->directory, &rdir->entry) > 0); #elif defined(__CELLOS_LV2__) @@ -152,7 +158,7 @@ const char *retro_dirent_get_name(struct RDIR *rdir) * Returns: true if directory listing entry is * a directory, false if not. */ -bool retro_dirent_is_dir(struct RDIR *rdir, const char *path) +bool retro_dirent_is_dir(struct RDIR *rdir) { #if defined(_WIN32) const WIN32_FIND_DATA *entry = (const WIN32_FIND_DATA*)&rdir->entry; @@ -172,11 +178,13 @@ bool retro_dirent_is_dir(struct RDIR *rdir, const char *path) if (entry->d_type == DT_DIR) return true; /* This can happen on certain file systems. */ + const char *path = retro_dirent_get_name(rdir); if (entry->d_type == DT_UNKNOWN || entry->d_type == DT_LNK) return path_is_directory(path); return false; #else /* dirent struct doesn't have d_type, do it the slow way ... */ + const char *path = retro_dirent_get_name(rdir); return path_is_directory(path); #endif } diff --git a/desmume/src/libretro-common/include/retro_dirent.h b/desmume/src/libretro-common/include/retro_dirent.h index a06a56d13..ca867cb19 100644 --- a/desmume/src/libretro-common/include/retro_dirent.h +++ b/desmume/src/libretro-common/include/retro_dirent.h @@ -43,14 +43,13 @@ const char *retro_dirent_get_name(struct RDIR *rdir); * * retro_dirent_is_dir: * @rdir : pointer to the directory entry. - * @path : path to the directory entry. * * Is the directory listing entry a directory? * * Returns: true if directory listing entry is * a directory, false if not. */ -bool retro_dirent_is_dir(struct RDIR *rdir, const char *path); +bool retro_dirent_is_dir(struct RDIR *rdir); void retro_closedir(struct RDIR *rdir); diff --git a/desmume/src/libretro-common/include/retro_stat.h b/desmume/src/libretro-common/include/retro_stat.h index 19be56069..37e4348e1 100644 --- a/desmume/src/libretro-common/include/retro_stat.h +++ b/desmume/src/libretro-common/include/retro_stat.h @@ -28,6 +28,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /** * path_is_directory: * @path : path @@ -54,4 +58,8 @@ int32_t path_get_size(const char *path); **/ bool mkdir_norecurse(const char *dir); +#ifdef __cplusplus +} +#endif + #endif diff --git a/desmume/src/libretro-common/lists/dir_list.c b/desmume/src/libretro-common/lists/dir_list.c index 8bcb3f3fb..5fb2b373e 100644 --- a/desmume/src/libretro-common/lists/dir_list.c +++ b/desmume/src/libretro-common/lists/dir_list.c @@ -188,7 +188,7 @@ struct string_list *dir_list_new(const char *dir, const char *file_ext = path_get_extension(name); fill_pathname_join(file_path, dir, name, sizeof(file_path)); - is_dir = retro_dirent_is_dir(entry, file_path); + is_dir = retro_dirent_is_dir(entry); ret = parse_dir_entry(name, file_path, is_dir, include_dirs, include_compressed, list, ext_list, file_ext);