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:
parent
cd702e32f3
commit
b03347dc48
|
@ -64,6 +64,7 @@ struct RDIR
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
WIN32_FIND_DATA entry;
|
WIN32_FIND_DATA entry;
|
||||||
HANDLE directory;
|
HANDLE directory;
|
||||||
|
bool next;
|
||||||
#elif defined(VITA) || defined(PSP)
|
#elif defined(VITA) || defined(PSP)
|
||||||
SceUID directory;
|
SceUID directory;
|
||||||
SceIoDirent entry;
|
SceIoDirent entry;
|
||||||
|
@ -118,7 +119,12 @@ bool retro_dirent_error(struct RDIR *rdir)
|
||||||
int retro_readdir(struct RDIR *rdir)
|
int retro_readdir(struct RDIR *rdir)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#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)
|
#elif defined(VITA) || defined(PSP)
|
||||||
return (sceIoDread(rdir->directory, &rdir->entry) > 0);
|
return (sceIoDread(rdir->directory, &rdir->entry) > 0);
|
||||||
#elif defined(__CELLOS_LV2__)
|
#elif defined(__CELLOS_LV2__)
|
||||||
|
@ -152,7 +158,7 @@ const char *retro_dirent_get_name(struct RDIR *rdir)
|
||||||
* Returns: true if directory listing entry is
|
* Returns: true if directory listing entry is
|
||||||
* a directory, false if not.
|
* 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)
|
#if defined(_WIN32)
|
||||||
const WIN32_FIND_DATA *entry = (const WIN32_FIND_DATA*)&rdir->entry;
|
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)
|
if (entry->d_type == DT_DIR)
|
||||||
return true;
|
return true;
|
||||||
/* This can happen on certain file systems. */
|
/* 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)
|
if (entry->d_type == DT_UNKNOWN || entry->d_type == DT_LNK)
|
||||||
return path_is_directory(path);
|
return path_is_directory(path);
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
/* dirent struct doesn't have d_type, do it the slow way ... */
|
/* 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);
|
return path_is_directory(path);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,14 +43,13 @@ const char *retro_dirent_get_name(struct RDIR *rdir);
|
||||||
*
|
*
|
||||||
* retro_dirent_is_dir:
|
* retro_dirent_is_dir:
|
||||||
* @rdir : pointer to the directory entry.
|
* @rdir : pointer to the directory entry.
|
||||||
* @path : path to the directory entry.
|
|
||||||
*
|
*
|
||||||
* Is the directory listing entry a directory?
|
* Is the directory listing entry a directory?
|
||||||
*
|
*
|
||||||
* Returns: true if directory listing entry is
|
* Returns: true if directory listing entry is
|
||||||
* a directory, false if not.
|
* 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);
|
void retro_closedir(struct RDIR *rdir);
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
|
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* path_is_directory:
|
* path_is_directory:
|
||||||
* @path : path
|
* @path : path
|
||||||
|
@ -54,4 +58,8 @@ int32_t path_get_size(const char *path);
|
||||||
**/
|
**/
|
||||||
bool mkdir_norecurse(const char *dir);
|
bool mkdir_norecurse(const char *dir);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -188,7 +188,7 @@ struct string_list *dir_list_new(const char *dir,
|
||||||
const char *file_ext = path_get_extension(name);
|
const char *file_ext = path_get_extension(name);
|
||||||
|
|
||||||
fill_pathname_join(file_path, dir, name, sizeof(file_path));
|
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,
|
ret = parse_dir_entry(name, file_path, is_dir,
|
||||||
include_dirs, include_compressed, list, ext_list, file_ext);
|
include_dirs, include_compressed, list, ext_list, file_ext);
|
||||||
|
|
Loading…
Reference in New Issue