summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-03-23 20:01:12 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-03-23 23:08:23 +0100
commit0391a2203100d1c6c45e8eb92f10ab625d66906b (patch)
tree3d5f2852cf5555ece83a0dcdc9eb91ef5adf0aa9
parent0ab67523777253387224bbcc038dedce7a64486d (diff)
downloadmanaserv-0391a2203100d1c6c45e8eb92f10ab625d66906b.tar.gz
manaserv-0391a2203100d1c6c45e8eb92f10ab625d66906b.tar.bz2
manaserv-0391a2203100d1c6c45e8eb92f10ab625d66906b.tar.xz
manaserv-0391a2203100d1c6c45e8eb92f10ab625d66906b.zip
Simplify implementation of fileExists
-rw-r--r--src/common/resourcemanager.cpp34
1 files changed, 8 insertions, 26 deletions
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)