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)

This commit is contained in:
zeromus 2016-04-22 01:38:26 +00:00
parent cd702e32f3
commit b03347dc48
4 changed files with 20 additions and 5 deletions

View File

@ -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
}

View File

@ -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);

View File

@ -28,6 +28,10 @@
#include <boolean.h>
#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

View File

@ -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);