Fix g_ascii_strdown usage

This commit is contained in:
Pan7 2017-08-08 01:24:41 +02:00
parent db467908ad
commit 7a936d6832
1 changed files with 14 additions and 9 deletions

View File

@ -133,6 +133,7 @@ static void vfsInitPakFile( const char *filename ){
for ( i = 0; i < gi.number_entry; i++ ) for ( i = 0; i < gi.number_entry; i++ )
{ {
char filename_inzip[NAME_MAX]; char filename_inzip[NAME_MAX];
char *filename_lower;
unz_file_info file_info; unz_file_info file_info;
VFS_PAKFILE* file; VFS_PAKFILE* file;
@ -145,9 +146,9 @@ static void vfsInitPakFile( const char *filename ){
g_pakFiles = g_slist_append( g_pakFiles, file ); g_pakFiles = g_slist_append( g_pakFiles, file );
vfsFixDOSName( filename_inzip ); vfsFixDOSName( filename_inzip );
g_ascii_strdown( filename_inzip, -1 );//-1 null terminated string filename_lower = g_ascii_strdown( filename_inzip, -1 );//-1 null terminated string
file->name = strdup( filename_inzip ); file->name = strdup( filename_lower );
file->size = file_info.uncompressed_size; file->size = file_info.uncompressed_size;
file->zipfile = uf; file->zipfile = uf;
memcpy( &file->zipinfo, uf, sizeof( unz_s ) ); memcpy( &file->zipinfo, uf, sizeof( unz_s ) );
@ -158,6 +159,7 @@ static void vfsInitPakFile( const char *filename ){
break; break;
} }
} }
g_free( filename_lower );
} }
} }
@ -232,17 +234,18 @@ void vfsShutdown(){
int vfsGetFileCount( const char *filename ){ int vfsGetFileCount( const char *filename ){
int i, count = 0; int i, count = 0;
char fixed[NAME_MAX], tmp[NAME_MAX]; char fixed[NAME_MAX], tmp[NAME_MAX];
char *lower;
GSList *lst; GSList *lst;
strcpy( fixed, filename ); strcpy( fixed, filename );
vfsFixDOSName( fixed ); vfsFixDOSName( fixed );
g_ascii_strdown( fixed, -1 ); lower = g_ascii_strdown( fixed, -1 );
for ( lst = g_pakFiles; lst != NULL; lst = g_slist_next( lst ) ) for ( lst = g_pakFiles; lst != NULL; lst = g_slist_next( lst ) )
{ {
VFS_PAKFILE* file = (VFS_PAKFILE*)lst->data; VFS_PAKFILE* file = (VFS_PAKFILE*)lst->data;
if ( strcmp( file->name, fixed ) == 0 ) { if ( strcmp( file->name, lower ) == 0 ) {
count++; count++;
} }
} }
@ -250,12 +253,12 @@ int vfsGetFileCount( const char *filename ){
for ( i = 0; i < g_numDirs; i++ ) for ( i = 0; i < g_numDirs; i++ )
{ {
strcpy( tmp, g_strDirs[i] ); strcpy( tmp, g_strDirs[i] );
strcat( tmp, fixed ); strcat( tmp, lower );
if ( access( tmp, R_OK ) == 0 ) { if ( access( tmp, R_OK ) == 0 ) {
count++; count++;
} }
} }
g_free( lower );
return count; return count;
} }
@ -263,6 +266,7 @@ int vfsGetFileCount( const char *filename ){
int vfsLoadFile( const char *filename, void **bufferptr, int index ){ int vfsLoadFile( const char *filename, void **bufferptr, int index ){
int i, count = 0; int i, count = 0;
char tmp[NAME_MAX], fixed[NAME_MAX]; char tmp[NAME_MAX], fixed[NAME_MAX];
char *lower;
GSList *lst; GSList *lst;
// filename is a full path // filename is a full path
@ -296,7 +300,7 @@ int vfsLoadFile( const char *filename, void **bufferptr, int index ){
*bufferptr = NULL; *bufferptr = NULL;
strcpy( fixed, filename ); strcpy( fixed, filename );
vfsFixDOSName( fixed ); vfsFixDOSName( fixed );
g_ascii_strdown( fixed, -1 ); lower = g_ascii_strdown( fixed, -1 );
for ( i = 0; i < g_numDirs; i++ ) for ( i = 0; i < g_numDirs; i++ )
{ {
@ -338,7 +342,7 @@ int vfsLoadFile( const char *filename, void **bufferptr, int index ){
{ {
VFS_PAKFILE* file = (VFS_PAKFILE*)lst->data; VFS_PAKFILE* file = (VFS_PAKFILE*)lst->data;
if ( strcmp( file->name, fixed ) != 0 ) { if ( strcmp( file->name, lower ) != 0 ) {
continue; continue;
} }
@ -359,12 +363,13 @@ int vfsLoadFile( const char *filename, void **bufferptr, int index ){
return -1; return -1;
} }
else{ else{
g_free( lower );
return file->size; return file->size;
} }
} }
count++; count++;
} }
g_free( lower );
return -1; return -1;
} }