summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2011-07-16 18:34:04 +0000
committeralberth <alberth@openttd.org>2011-07-16 18:34:04 +0000
commit20c2b5fdde6f3f70dc0a955ef803b8a0fa21e0e5 (patch)
treeb00806e9a2bb60f507eaa9ca10f5bfd5f519d56b /src
parentd209369c50098f6c17afb3eaffb162e86d6e01bb (diff)
downloadopenttd-20c2b5fdde6f3f70dc0a955ef803b8a0fa21e0e5.tar.xz
(svn r22668) -Codechange: FioFindFullPath tests already whether the file exists.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp
index 0517ca36d..2b0f67b1e 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -300,6 +300,14 @@ char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdi
return buf;
}
+/**
+ * Find a path to the filename in one of the search directories.
+ * @param buf [out] Destination buffer for the path.
+ * @param buflen Length of the destination buffer.
+ * @param subdir Subdirectory to try.
+ * @param filename Filename to look for.
+ * @return \a buf containing the path if the path was found, else \c NULL.
+ */
char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename)
{
Searchpath sp;
@@ -307,17 +315,17 @@ char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char
FOR_ALL_SEARCHPATHS(sp) {
FioGetFullPath(buf, buflen, sp, subdir, filename);
- if (FileExists(buf)) break;
+ if (FileExists(buf)) return buf;
#if !defined(WIN32)
/* Be, as opening files, aware that sometimes the filename
* might be in uppercase when it is in lowercase on the
* disk. Ofcourse Windows doesn't care about casing. */
strtolower(buf + strlen(_searchpaths[sp]) - 1);
- if (FileExists(buf)) break;
+ if (FileExists(buf)) return buf;
#endif
}
- return buf;
+ return NULL;
}
char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir)
@@ -1049,9 +1057,7 @@ void DeterminePaths(const char *exe)
}
} else {
char personal_dir[MAX_PATH];
- FioFindFullPath(personal_dir, lengthof(personal_dir), BASE_DIR, "openttd.cfg");
-
- if (FileExists(personal_dir)) {
+ if (FioFindFullPath(personal_dir, lengthof(personal_dir), BASE_DIR, "openttd.cfg") != NULL) {
char *end = strrchr(personal_dir, PATHSEPCHAR);
if (end != NULL) end[1] = '\0';
_personal_dir = strdup(personal_dir);