diff options
author | Max Horn | 2003-06-14 18:20:56 +0000 |
---|---|---|
committer | Max Horn | 2003-06-14 18:20:56 +0000 |
commit | 9658dd6ea367ce71e1928003236c1801c5e3b1ee (patch) | |
tree | 200f8cd592d202fc37ec71d3a43fb866cdd681ff /common/file.cpp | |
parent | a4edad02b6da4c41410ec045b592a51bba5f581c (diff) | |
download | scummvm-rg350-9658dd6ea367ce71e1928003236c1801c5e3b1ee.tar.gz scummvm-rg350-9658dd6ea367ce71e1928003236c1801c5e3b1ee.tar.bz2 scummvm-rg350-9658dd6ea367ce71e1928003236c1801c5e3b1ee.zip |
fixed aquadran's Windows fix (a pointer is const for good reasons; simply casting it to something non-const is bad, and undermines the compilers aliasing detection
svn-id: r8481
Diffstat (limited to 'common/file.cpp')
-rw-r--r-- | common/file.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/common/file.cpp b/common/file.cpp index 037871ad16..f73a5e37be 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -20,6 +20,7 @@ */ #include "file.h" +#include "util.h" #include "engine.h" // For debug/warning/error FILE *File::fopenNoCase(const char *filename, const char *directory, const char *mode) { @@ -27,16 +28,22 @@ FILE *File::fopenNoCase(const char *filename, const char *directory, const char char buf[256]; char *ptr; + strcpy(buf, directory); + +#ifdef _MSC_VER // FIXME: is there a better check to detect Windows ?! // Fix for Win98 issue related with game directory pointing to root drive ex. "c:\" - ptr = (char*)directory; - if ((ptr[1] == ':') && (ptr[2] == '\\') && (ptr[3] == 0)) { - ptr[2] = 0; + if (buf[0] != 0) && (buf[1] == ':') && (buf[2] == '\\') && (buf[3] == 0)) { + buf[2] = 0; } +#endif - strcpy(buf, directory); - if (directory[0] != 0) { + // Record the length of the dir name (so we can cut of anything trailing it + // later, when we try with different file names). + const int dirLen = strlen(buf); + + if (dirLen > 0) { #ifdef __MORPHOS__ - if (buf[strlen(buf)-1] != ':' && buf[strlen(buf)-1] != '/') + if (buf[dirLen-1] != ':' && buf[dirLen-1] != '/') #endif #if !defined(__GP32__) && !defined(__PALM_OS__) @@ -61,9 +68,9 @@ FILE *File::fopenNoCase(const char *filename, const char *directory, const char "VOICES/" }; - for (uint8 l = 0; l < 9; l++) { - strcpy(buf, directory); - if (directory[0] != 0) { + for (int dirIdx = 0; dirIdx < ARRAYSIZE(dirs); dirIdx++) { + buf[dirLen] = 0; + if (buf[0] != 0) { #ifdef __MORPHOS__ if (buf[strlen(buf) - 1] != ':' && buf[strlen(buf) - 1] != '/') #endif @@ -71,7 +78,7 @@ FILE *File::fopenNoCase(const char *filename, const char *directory, const char strcat(buf, "/"); // PALMOS #endif } - strcat(buf, dirs[l]); + strcat(buf, dirs[dirIdx]); int8 len = strlen(buf); strcat(buf, filename); |