From 0391a2203100d1c6c45e8eb92f10ab625d66906b Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Wed, 23 Mar 2011 20:01:12 +0100 Subject: Simplify implementation of fileExists --- src/common/resourcemanager.cpp | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/common/resourcemanager.cpp b/src/common/resourcemanager.cpp index b32c6ff7..5c177f72 100644 --- a/src/common/resourcemanager.cpp +++ b/src/common/resourcemanager.cpp @@ -55,34 +55,16 @@ void ResourceManager::initialize() } /** - * This function tries to check if a file exists - * based on the existence of stats about it. - * Because simply trying to open it and check for failure - * is a bad thing, as you don't know if you weren't able - * to open it because it doesn't exist or because - * you don't have the right to. + * This function tries to check if a file exists based on the existence of + * stats about it. Because simply trying to open it and check for failure is a + * bad thing, as you don't know if you weren't able to open it because it + * doesn't exist or because you don't have the right to. */ -static bool fileExists(const std::string& filename) +static bool fileExists(const std::string &filename) { - struct stat fileStat; - bool fileExist = false; - int statValue = -1; - - // Try to get the file attributes - statValue = stat(filename.c_str(), &fileStat); - - if(statValue == 0) - { - // The file attributes exists, so the file does, too. - fileExist = true; - } - else - { - // Impossible to get the file attributes. - fileExist = false; - } - - return fileExist; + struct stat buffer; + // When stat is succesful, the file exists + return stat(filename.c_str(), &buffer) == 0; } bool ResourceManager::exists(const std::string &path, bool lookInSearchPath) -- cgit v1.2.3-70-g09d2