Skip to content

Commit 3b0c90a

Browse files
committed
Bring back ToLowerCase hack, as it covers cases with directories and subdirectories. But make it more safe!
1 parent e284f73 commit 3b0c90a

File tree

3 files changed

+36
-37
lines changed

3 files changed

+36
-37
lines changed

engine/common/build.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ GNU General Public License for more details.
1818
#define XASH_GENERATE_BUILDNUM
1919

2020
#if defined(XASH_GENERATE_BUILDNUM)
21-
static char *date = __DATE__ ;
21+
static char *date = __DATE__;
2222
static char *mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
2323
static char mond[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
2424
#endif

engine/common/common.h

-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,6 @@ int matchpattern( const char *in, const char *pattern, qboolean caseinsensitive
459459
int matchpattern_with_separator( const char *in, const char *pattern, qboolean caseinsensitive, const char *separators, qboolean wildcard_least_one );
460460
void FS_Init( void );
461461
void FS_Path( void );
462-
char *FS_ToLowerCase( const char *path );
463462
void FS_Shutdown( void );
464463
void FS_ClearSearchPath( void );
465464
void FS_AllowDirectPaths( qboolean enable );

engine/common/filesystem.c

+35-35
Original file line numberDiff line numberDiff line change
@@ -1984,20 +1984,21 @@ FS_ToLowerCase
19841984
Function to set all characters of path lowercase
19851985
====================
19861986
*/
1987-
char* FS_ToLowerCase( const char* path )
1987+
static char* FS_ToLowerCase( const char* path )
19881988
{
1989-
if (path) {
1990-
char *result = malloc(strlen(path) + 1);
1991-
int i = 0;
1992-
while( path[i] )
1993-
{
1994-
result[i] = tolower( path[i] );
1995-
++i;
1996-
}
1997-
result[i] = '\0';
1998-
return result;
1989+
static char path2[MAX_SYSPATH];
1990+
int i;
1991+
1992+
ASSERT( path );
1993+
1994+
for( i = 0; path[i]; i++ )
1995+
{
1996+
path2[i] = Q_tolower( path[i] );
19991997
}
2000-
return NULL;
1998+
1999+
path2[i] = 0;
2000+
2001+
return path2;
20012002
}
20022003

20032004
/*
@@ -2753,22 +2754,23 @@ byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamediro
27532754

27542755
file = FS_Open( path, "rb", gamedironly );
27552756

2757+
#ifndef _WIN32
27562758
if( !file )
27572759
{
27582760
// Try to open this file with lowered path
2759-
char *loweredPath = FS_ToLowerCase( path );
2760-
file = FS_Open( loweredPath, "rb", gamedironly );
2761-
free(loweredPath);
2762-
if( !file )
2763-
{
2764-
// Now it truly doesn't exist in file system
2765-
buf = W_LoadFile( path, &filesize, gamedironly );
2761+
file = FS_Open( FS_ToLowerCase( path ), "rb", gamedironly );
2762+
}
2763+
#endif // _WIN32
2764+
2765+
if( !file )
2766+
{
2767+
// Now it truly doesn't exist in file system
2768+
buf = W_LoadFile( path, &filesize, gamedironly );
27662769

2767-
if( filesizeptr )
2768-
*filesizeptr = filesize;
2770+
if( filesizeptr )
2771+
*filesizeptr = filesize;
27692772

2770-
return buf;
2771-
}
2773+
return buf;
27722774
}
27732775

27742776
// Try to load
@@ -2800,17 +2802,17 @@ byte *FS_LoadDirectFile( const char *path, fs_offset_t *filesizeptr )
28002802

28012803
file = FS_SysOpen( path, "rb" );
28022804

2805+
#ifndef _WIN32
28032806
if( !file )
28042807
{
28052808
// Try to open this file with lowered path
2806-
char *loweredPath = FS_ToLowerCase( path );
2807-
file = FS_SysOpen( loweredPath, "rb" );
2808-
free(loweredPath);
2809-
if( !file )
2810-
{
2811-
return NULL;
2812-
}
2809+
file = FS_SysOpen( FS_ToLowerCase( path ), "rb" );
28132810
}
2811+
#endif // _WIN32
2812+
2813+
if( !file )
2814+
return NULL;
2815+
28142816

28152817
// Try to load
28162818
filesize = file->real_length;
@@ -2836,12 +2838,10 @@ file_t *FS_OpenFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedi
28362838
{
28372839
file_t *file = FS_Open( path, "rb", gamedironly );
28382840

2841+
#ifndef _WIN32
28392842
if( !file )
2840-
{
2841-
char *loweredPath = FS_ToLowerCase( path );
2842-
file = FS_Open( loweredPath, "rb", gamedironly );
2843-
free(loweredPath);
2844-
}
2843+
file = FS_Open( FS_ToLowerCase( path ), "rb", gamedironly );
2844+
#endif // _WIN32
28452845

28462846
if( filesizeptr )
28472847
{

0 commit comments

Comments
 (0)