mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
FileUtil: Don't manually strip trailing slashes
POSIX allows one or more trailing slashes for directories. From POSIX.1-2008, section 3.271 (Base Definitions / Pathname): > A pathname can optionally contain one or more trailing <slash> > characters. Multiple successive <slash> characters are considered to > be the same as one <slash>, except for the case of exactly two > leading <slash> characters. On Windows, the extra trailing slashes are ignored for directories too.
This commit is contained in:
@ -51,29 +51,15 @@
|
|||||||
// REMEMBER: strdup considered harmful!
|
// REMEMBER: strdup considered harmful!
|
||||||
namespace File
|
namespace File
|
||||||
{
|
{
|
||||||
// Remove any ending forward slashes from directory paths
|
|
||||||
// Modifies argument.
|
|
||||||
static void StripTailDirSlashes(std::string& fname)
|
|
||||||
{
|
|
||||||
if (fname.length() > 1)
|
|
||||||
{
|
|
||||||
while (fname.back() == DIR_SEP_CHR)
|
|
||||||
fname.pop_back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if file filename exists
|
// Returns true if file filename exists
|
||||||
bool Exists(const std::string& filename)
|
bool Exists(const std::string& filename)
|
||||||
{
|
{
|
||||||
struct stat file_info;
|
struct stat file_info;
|
||||||
|
|
||||||
std::string copy(filename);
|
|
||||||
StripTailDirSlashes(copy);
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int result = _tstat64(UTF8ToTStr(copy).c_str(), &file_info);
|
int result = _tstat64(UTF8ToTStr(filename).c_str(), &file_info);
|
||||||
#else
|
#else
|
||||||
int result = stat(copy.c_str(), &file_info);
|
int result = stat(filename.c_str(), &file_info);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return (result == 0);
|
return (result == 0);
|
||||||
@ -84,13 +70,10 @@ bool IsDirectory(const std::string& filename)
|
|||||||
{
|
{
|
||||||
struct stat file_info;
|
struct stat file_info;
|
||||||
|
|
||||||
std::string copy(filename);
|
|
||||||
StripTailDirSlashes(copy);
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int result = _tstat64(UTF8ToTStr(copy).c_str(), &file_info);
|
int result = _tstat64(UTF8ToTStr(filename).c_str(), &file_info);
|
||||||
#else
|
#else
|
||||||
int result = stat(copy.c_str(), &file_info);
|
int result = stat(filename.c_str(), &file_info);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
|
Reference in New Issue
Block a user