summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/files.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-12-02 11:07:32 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-12-02 11:07:32 +0000
commit1569534656650a35d462f84665db3f089dd1e7ea (patch)
treefd73414345ba61b69819cf5eedee013f9b513b53 /crawl-ref/source/files.cc
parent278c7d69e18bc2a10e2530e703164587936328dc (diff)
downloadcrawl-ref-1569534656650a35d462f84665db3f089dd1e7ea.tar.gz
crawl-ref-1569534656650a35d462f84665db3f089dd1e7ea.zip
Add a section on where Crawl looks for its data files to INSTALL. Use stat where possible instead of opening files, cleaned up handling of DATA_DIR_PATH when searching for data files.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2965 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/files.cc')
-rw-r--r--crawl-ref/source/files.cc16
1 files changed, 15 insertions, 1 deletions
diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc
index bf82b47e10..2f845fff44 100644
--- a/crawl-ref/source/files.cc
+++ b/crawl-ref/source/files.cc
@@ -47,7 +47,6 @@
#ifdef __MINGW32__
#include <io.h>
-#include <sys/types.h>
#endif
#include <sys/types.h>
@@ -93,6 +92,12 @@
#include "view.h"
#include "xom.h"
+#ifndef HAVE_STAT
+#if defined(UNIX) || defined(__MINGW32__) || defined(DOS)
+#define HAVE_STAT
+#endif
+#endif
+
void save_level(int level_saved, level_area_type lt,
branch_type where_were_you);
@@ -288,11 +293,17 @@ void check_newer(const std::string &target,
static bool file_exists(const std::string &name)
{
+#ifdef HAVE_STAT
+ struct stat st;
+ const int err = ::stat(name.c_str(), &st);
+ return (!err);
+#else
FILE *f = fopen(name.c_str(), "r");
const bool exists = !!f;
if (f)
fclose(f);
return (exists);
+#endif
}
// Low-tech existence check.
@@ -369,8 +380,11 @@ std::string datafile_path(std::string basename,
const std::string prefixes[] = {
std::string("dat") + FILE_SEPARATOR,
std::string("docs") + FILE_SEPARATOR,
+#ifndef DATA_DIR_PATH
std::string("..") + FILE_SEPARATOR + "docs" + FILE_SEPARATOR,
+ std::string("..") + FILE_SEPARATOR + "dat" + FILE_SEPARATOR,
std::string("..") + FILE_SEPARATOR,
+#endif
std::string(".") + FILE_SEPARATOR,
"",
};