Cleanup retro_dirent_is_dir

This commit is contained in:
twinaphex 2017-08-06 14:21:18 +02:00
parent 7382a38485
commit c7e6f19920
1 changed files with 9 additions and 45 deletions

View File

@ -157,45 +157,6 @@ const char *retro_dirent_get_name(struct RDIR *rdir)
#endif #endif
} }
static bool path_is_directory_internal(const char *path)
{
#if defined(VITA) || defined(PSP)
SceIoStat buf;
char *tmp = strdup(path);
size_t len = strlen(tmp);
if (tmp[len-1] == '/')
tmp[len-1]='\0';
if (sceIoGetstat(tmp, &buf) < 0)
{
free(tmp);
return false;
}
free(tmp);
return FIO_S_ISDIR(buf.st_mode);
#elif defined(__CELLOS_LV2__)
CellFsStat buf;
if (cellFsStat(path, &buf) < 0)
return false;
return ((buf.st_mode & S_IFMT) == S_IFDIR);
#elif defined(_WIN32)
struct _stat buf;
DWORD file_info = GetFileAttributes(path);
_stat(path, &buf);
if (file_info == INVALID_FILE_ATTRIBUTES)
return false;
return (file_info & FILE_ATTRIBUTE_DIRECTORY);
#else
struct stat buf;
if (stat(path, &buf) < 0)
return false;
return S_ISDIR(buf.st_mode);
#endif
}
/** /**
* *
* retro_dirent_is_dir: * retro_dirent_is_dir:
@ -222,17 +183,20 @@ bool retro_dirent_is_dir(struct RDIR *rdir, const char *path)
#elif defined(__CELLOS_LV2__) #elif defined(__CELLOS_LV2__)
CellFsDirent *entry = (CellFsDirent*)&rdir->entry; CellFsDirent *entry = (CellFsDirent*)&rdir->entry;
return (entry->d_type == CELL_FS_TYPE_DIRECTORY); return (entry->d_type == CELL_FS_TYPE_DIRECTORY);
#elif defined(DT_DIR) #else
struct stat buf;
#if defined(DT_DIR)
const struct dirent *entry = (const struct dirent*)rdir->entry; const struct dirent *entry = (const struct dirent*)rdir->entry;
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. */
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_internal(path); return false;
return false; #endif
#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 ... */
return path_is_directory_internal(path); if (stat(path, &buf) < 0)
return false;
return S_ISDIR(buf.st_mode);
#endif #endif
} }