[Scummvm-cvs-logs] CVS: scummvm/common file.cpp,1.33,1.34
Max Horn
fingolfin at users.sourceforge.net
Sat Jun 14 11:21:16 CEST 2003
Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1:/tmp/cvs-serv7877
Modified Files:
file.cpp
Log Message:
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
Index: file.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/file.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- file.cpp 14 Jun 2003 16:45:38 -0000 1.33
+++ file.cpp 14 Jun 2003 18:20:56 -0000 1.34
@@ -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 @@
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 @@
"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 @@
strcat(buf, "/"); // PALMOS
#endif
}
- strcat(buf, dirs[l]);
+ strcat(buf, dirs[dirIdx]);
int8 len = strlen(buf);
strcat(buf, filename);
More information about the Scummvm-git-logs
mailing list