From 1569534656650a35d462f84665db3f089dd1e7ea Mon Sep 17 00:00:00 2001 From: dshaligram Date: Sun, 2 Dec 2007 11:07:32 +0000 Subject: 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 --- crawl-ref/source/files.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'crawl-ref/source/files.cc') 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 -#include #endif #include @@ -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, "", }; -- cgit v1.2.3-54-g00ecf