Skip to content

Commit

Permalink
Merge pull request #5625 from leoetlino/fileutil-fixes
Browse files Browse the repository at this point in the history
FileUtil fixes
  • Loading branch information
leoetlino committed Jun 16, 2017
2 parents 37208d2 + 01faa5c commit cc9bd0b
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions Source/Core/Common/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,15 @@
// REMEMBER: strdup considered harmful!
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
bool Exists(const std::string& filename)
{
struct stat file_info;

std::string copy(filename);
StripTailDirSlashes(copy);

#ifdef _WIN32
int result = _tstat64(UTF8ToTStr(copy).c_str(), &file_info);
int result = _tstat64(UTF8ToTStr(filename).c_str(), &file_info);
#else
int result = stat(copy.c_str(), &file_info);
int result = stat(filename.c_str(), &file_info);
#endif

return (result == 0);
Expand All @@ -84,19 +70,15 @@ bool IsDirectory(const std::string& filename)
{
struct stat file_info;

std::string copy(filename);
StripTailDirSlashes(copy);

#ifdef _WIN32
int result = _tstat64(UTF8ToTStr(copy).c_str(), &file_info);
int result = _tstat64(UTF8ToTStr(filename).c_str(), &file_info);
#else
int result = stat(copy.c_str(), &file_info);
int result = stat(filename.c_str(), &file_info);
#endif

if (result < 0)
{
WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s", filename.c_str(),
GetLastErrorMsg().c_str());
WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s", filename.c_str(), strerror(errno));
return false;
}

Expand Down

0 comments on commit cc9bd0b

Please sign in to comment.