mirror of
https://github.com/libretro/RetroArch
synced 2025-03-22 07:21:15 +00:00
(VFS/libretro-common) Cleanups
This commit is contained in:
parent
8debf4b88e
commit
a9733ab418
@ -740,15 +740,11 @@ int retro_vfs_file_remove_impl(const char *path)
|
|||||||
{
|
{
|
||||||
#if defined(_WIN32) && !defined(_XBOX)
|
#if defined(_WIN32) && !defined(_XBOX)
|
||||||
/* Win32 (no Xbox) */
|
/* Win32 (no Xbox) */
|
||||||
|
|
||||||
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500
|
|
||||||
char *path_local = NULL;
|
|
||||||
#else
|
|
||||||
wchar_t *path_wide = NULL;
|
|
||||||
#endif
|
|
||||||
if (!path || !*path)
|
if (!path || !*path)
|
||||||
return -1;
|
return -1;
|
||||||
|
{
|
||||||
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500
|
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500
|
||||||
|
char *path_local = NULL;
|
||||||
if ((path_local = utf8_to_local_string_alloc(path)))
|
if ((path_local = utf8_to_local_string_alloc(path)))
|
||||||
{
|
{
|
||||||
int ret = remove(path_local);
|
int ret = remove(path_local);
|
||||||
@ -758,6 +754,7 @@ int retro_vfs_file_remove_impl(const char *path)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
wchar_t *path_wide = NULL;
|
||||||
if ((path_wide = utf8_to_utf16_string_alloc(path)))
|
if ((path_wide = utf8_to_utf16_string_alloc(path)))
|
||||||
{
|
{
|
||||||
int ret = _wremove(path_wide);
|
int ret = _wremove(path_wide);
|
||||||
@ -767,6 +764,7 @@ int retro_vfs_file_remove_impl(const char *path)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if (remove(path) == 0)
|
if (remove(path) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@ -842,96 +840,78 @@ const char *retro_vfs_file_get_path_impl(
|
|||||||
|
|
||||||
int retro_vfs_stat_impl(const char *path, int32_t *size)
|
int retro_vfs_stat_impl(const char *path, int32_t *size)
|
||||||
{
|
{
|
||||||
bool is_dir = false;
|
int ret = RETRO_VFS_STAT_IS_VALID;
|
||||||
bool is_character_special = false;
|
|
||||||
#if defined(VITA)
|
|
||||||
/* Vita / PSP */
|
|
||||||
SceIoStat buf;
|
|
||||||
int dir_ret;
|
|
||||||
char *tmp = NULL;
|
|
||||||
size_t len = 0;
|
|
||||||
|
|
||||||
if (!path || !*path)
|
if (!path || !*path)
|
||||||
return 0;
|
return 0;
|
||||||
|
{
|
||||||
tmp = strdup(path);
|
#if defined(VITA)
|
||||||
len = strlen(tmp);
|
/* Vita / PSP */
|
||||||
|
SceIoStat stat_buf;
|
||||||
|
int dir_ret;
|
||||||
|
char *tmp = strdup(path);
|
||||||
|
size_t len = strlen(tmp);
|
||||||
if (tmp[len-1] == '/')
|
if (tmp[len-1] == '/')
|
||||||
tmp[len-1] = '\0';
|
tmp[len-1] = '\0';
|
||||||
|
|
||||||
dir_ret = sceIoGetstat(tmp, &buf);
|
dir_ret = sceIoGetstat(tmp, &stat_buf);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
if (dir_ret < 0)
|
if (dir_ret < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
*size = (int32_t)buf.st_size;
|
*size = (int32_t)stat_buf.st_size;
|
||||||
|
|
||||||
is_dir = FIO_S_ISDIR(buf.st_mode);
|
if (FIO_S_ISDIR(stat_buf.st_mode))
|
||||||
|
ret |= RETRO_VFS_STAT_IS_DIRECTORY;
|
||||||
#elif defined(__PSL1GHT__) || defined(__PS3__)
|
#elif defined(__PSL1GHT__) || defined(__PS3__)
|
||||||
/* Lowlevel Lv2 */
|
/* Lowlevel Lv2 */
|
||||||
sysFSStat buf;
|
sysFSStat stat_buf;
|
||||||
|
|
||||||
if (!path || !*path)
|
|
||||||
return 0;
|
|
||||||
if (sysFsStat(path, &buf) < 0)
|
if (sysFsStat(path, &buf) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
*size = (int32_t)buf.st_size;
|
*size = (int32_t)stat_buf.st_size;
|
||||||
|
|
||||||
is_dir = ((buf.st_mode & S_IFMT) == S_IFDIR);
|
if ((stat_buf.st_mode & S_IFMT) == S_IFDIR)
|
||||||
|
ret |= RETRO_VFS_STAT_IS_DIRECTORY;
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
/* Windows */
|
/* Windows */
|
||||||
DWORD file_info;
|
struct _stat stat_buf;
|
||||||
struct _stat buf;
|
|
||||||
#if defined(LEGACY_WIN32)
|
#if defined(LEGACY_WIN32)
|
||||||
char *path_local = NULL;
|
char *path_local = utf8_to_local_string_alloc(path);
|
||||||
#else
|
DWORD file_info = GetFileAttributes(path_local);
|
||||||
wchar_t *path_wide = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!path || !*path)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
#if defined(LEGACY_WIN32)
|
|
||||||
path_local = utf8_to_local_string_alloc(path);
|
|
||||||
file_info = GetFileAttributes(path_local);
|
|
||||||
|
|
||||||
if (!string_is_empty(path_local))
|
if (!string_is_empty(path_local))
|
||||||
_stat(path_local, &buf);
|
_stat(path_local, &stat_buf);
|
||||||
|
|
||||||
if (path_local)
|
if (path_local)
|
||||||
free(path_local);
|
free(path_local);
|
||||||
#else
|
#else
|
||||||
path_wide = utf8_to_utf16_string_alloc(path);
|
wchar_t *path_wide = utf8_to_utf16_string_alloc(path);
|
||||||
file_info = GetFileAttributesW(path_wide);
|
DWORD file_info = GetFileAttributesW(path_wide);
|
||||||
|
|
||||||
_wstat(path_wide, &buf);
|
_wstat(path_wide, &stat_buf);
|
||||||
|
|
||||||
if (path_wide)
|
if (path_wide)
|
||||||
free(path_wide);
|
free(path_wide);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (file_info == INVALID_FILE_ATTRIBUTES)
|
if (file_info == INVALID_FILE_ATTRIBUTES)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
*size = (int32_t)buf.st_size;
|
*size = (int32_t)stat_buf.st_size;
|
||||||
|
|
||||||
is_dir = (file_info & FILE_ATTRIBUTE_DIRECTORY);
|
|
||||||
|
|
||||||
|
if (file_info & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
ret |= RETRO_VFS_STAT_IS_DIRECTORY;
|
||||||
#elif defined(GEKKO)
|
#elif defined(GEKKO)
|
||||||
/* On GEKKO platforms, paths cannot have
|
/* On GEKKO platforms, paths cannot have
|
||||||
* trailing slashes - we must therefore
|
* trailing slashes - we must therefore
|
||||||
* remove them */
|
* remove them */
|
||||||
char *path_buf = NULL;
|
|
||||||
int stat_ret = -1;
|
|
||||||
struct stat stat_buf;
|
|
||||||
size_t len;
|
size_t len;
|
||||||
|
char *path_buf = NULL;
|
||||||
if (string_is_empty(path))
|
struct stat stat_buf;
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!(path_buf = strdup(path)))
|
if (!(path_buf = strdup(path)))
|
||||||
return 0;
|
return 0;
|
||||||
@ -940,34 +920,35 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
|
|||||||
if (path_buf[len - 1] == '/')
|
if (path_buf[len - 1] == '/')
|
||||||
path_buf[len - 1] = '\0';
|
path_buf[len - 1] = '\0';
|
||||||
|
|
||||||
stat_ret = stat(path_buf, &stat_buf);
|
|
||||||
free(path_buf);
|
free(path_buf);
|
||||||
|
|
||||||
if (stat_ret < 0)
|
if (stat(path_buf, &stat_buf) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
*size = (int32_t)stat_buf.st_size;
|
*size = (int32_t)stat_buf.st_size;
|
||||||
|
|
||||||
is_dir = S_ISDIR(stat_buf.st_mode);
|
if (S_ISDIR(stat_buf.st_mode))
|
||||||
is_character_special = S_ISCHR(stat_buf.st_mode);
|
ret |= RETRO_VFS_STAT_IS_DIRECTORY;
|
||||||
|
if (S_ISCHR(stat_buf.st_mode))
|
||||||
|
ret |= RETRO_VFS_STAT_IS_CHARACTER_SPECIAL;
|
||||||
#else
|
#else
|
||||||
/* Every other platform */
|
/* Every other platform */
|
||||||
struct stat buf;
|
struct stat stat_buf;
|
||||||
|
|
||||||
if (!path || !*path)
|
if (stat(path, &stat_buf) < 0)
|
||||||
return 0;
|
|
||||||
if (stat(path, &buf) < 0)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
*size = (int32_t)buf.st_size;
|
*size = (int32_t)stat_buf.st_size;
|
||||||
|
|
||||||
is_dir = S_ISDIR(buf.st_mode);
|
if (S_ISDIR(stat_buf.st_mode))
|
||||||
is_character_special = S_ISCHR(buf.st_mode);
|
ret |= RETRO_VFS_STAT_IS_DIRECTORY;
|
||||||
|
if (S_ISCHR(stat_buf.st_mode))
|
||||||
|
ret |= RETRO_VFS_STAT_IS_CHARACTER_SPECIAL;
|
||||||
#endif
|
#endif
|
||||||
return RETRO_VFS_STAT_IS_VALID | (is_dir ? RETRO_VFS_STAT_IS_DIRECTORY : 0) | (is_character_special ? RETRO_VFS_STAT_IS_CHARACTER_SPECIAL : 0);
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(VITA)
|
#if defined(VITA)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user