mirror of
https://github.com/libretro/RetroArch
synced 2025-04-07 13:23:32 +00:00
retro_stat.c - simplify code
This commit is contained in:
parent
ff1078a98b
commit
df13e6a1fd
@ -75,7 +75,8 @@
|
|||||||
enum stat_mode
|
enum stat_mode
|
||||||
{
|
{
|
||||||
IS_DIRECTORY = 0,
|
IS_DIRECTORY = 0,
|
||||||
IS_CHARACTER_SPECIAL
|
IS_CHARACTER_SPECIAL,
|
||||||
|
IS_VALID
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool path_stat(const char *path, enum stat_mode mode)
|
static bool path_stat(const char *path, enum stat_mode mode)
|
||||||
@ -90,6 +91,8 @@ static bool path_stat(const char *path, enum stat_mode mode)
|
|||||||
return false;
|
return false;
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
DWORD ret = GetFileAttributes(path);
|
DWORD ret = GetFileAttributes(path);
|
||||||
|
if (ret == INVALID_FILE_ATTRIBUTES)
|
||||||
|
return false;
|
||||||
#else
|
#else
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
if (stat(path, &buf) < 0)
|
if (stat(path, &buf) < 0)
|
||||||
@ -104,7 +107,7 @@ static bool path_stat(const char *path, enum stat_mode mode)
|
|||||||
#elif defined(__CELLOS_LV2__)
|
#elif defined(__CELLOS_LV2__)
|
||||||
return ((buf.st_mode & S_IFMT) == S_IFDIR);
|
return ((buf.st_mode & S_IFMT) == S_IFDIR);
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
return (ret & FILE_ATTRIBUTE_DIRECTORY) && (ret != INVALID_FILE_ATTRIBUTES);
|
return (ret & FILE_ATTRIBUTE_DIRECTORY);
|
||||||
#else
|
#else
|
||||||
return S_ISDIR(buf.st_mode);
|
return S_ISDIR(buf.st_mode);
|
||||||
#endif
|
#endif
|
||||||
@ -114,6 +117,8 @@ static bool path_stat(const char *path, enum stat_mode mode)
|
|||||||
#else
|
#else
|
||||||
return S_ISCHR(buf.st_mode);
|
return S_ISCHR(buf.st_mode);
|
||||||
#endif
|
#endif
|
||||||
|
case IS_VALID:
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -137,6 +142,11 @@ bool path_is_character_special(const char *path)
|
|||||||
return path_stat(path, IS_CHARACTER_SPECIAL);
|
return path_stat(path, IS_CHARACTER_SPECIAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool stat_is_valid(const char *path)
|
||||||
|
{
|
||||||
|
return path_stat(path, IS_VALID);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* path_mkdir_norecurse:
|
* path_mkdir_norecurse:
|
||||||
* @dir : directory
|
* @dir : directory
|
||||||
@ -169,26 +179,3 @@ bool mkdir_norecurse(const char *dir)
|
|||||||
printf("mkdir(%s) error: %s.\n", dir, strerror(errno));
|
printf("mkdir(%s) error: %s.\n", dir, strerror(errno));
|
||||||
return ret == 0;
|
return ret == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool stat_is_valid(const char *path)
|
|
||||||
{
|
|
||||||
#if defined(VITA) || defined(PSP)
|
|
||||||
SceIoStat buf;
|
|
||||||
if (sceIoGetstat(path, &buf) < 0)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
#elif defined(__CELLOS_LV2__)
|
|
||||||
CellFsStat buf;
|
|
||||||
if (cellFsStat(path, &buf) < 0)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
DWORD ret = GetFileAttributes(path);
|
|
||||||
return (ret != INVALID_FILE_ATTRIBUTES);
|
|
||||||
#else
|
|
||||||
struct stat buf;
|
|
||||||
if (stat(path, &buf) < 0)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user