Fixed loading non gzipped roms, thanks to mnk for the report

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@846 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
bgk 2009-01-04 13:32:18 +00:00
parent 2495a7b9d9
commit a6e74b1e7b
1 changed files with 6 additions and 3 deletions

View File

@ -40,11 +40,14 @@ static const char* get_gzip_size( const char* path, long* eof )
return "Couldn't open file"; return "Couldn't open file";
unsigned char buf [4]; unsigned char buf [4];
int res;
if ( fread( buf, 2, 1, file ) > 0 && buf [0] == 0x1F && buf [1] == 0x8B ) if ( fread( buf, 2, 1, file ) > 0 && buf [0] == 0x1F && buf [1] == 0x8B )
{ {
fseek( file, -4, SEEK_END ); fseek( file, -4, SEEK_END );
res = fread( buf, 4, 1, file ); if ( !fread( buf, 4, 1, file ) )
{
fclose( file );
return "Couldn't get file size";
}
*eof = buf [3] * 0x1000000 + buf [2] * 0x10000 + buf [1] * 0x100 + buf [0]; *eof = buf [3] * 0x1000000 + buf [2] * 0x10000 + buf [1] * 0x100 + buf [0];
} }
else else
@ -52,7 +55,7 @@ static const char* get_gzip_size( const char* path, long* eof )
fseek( file, 0, SEEK_END ); fseek( file, 0, SEEK_END );
*eof = ftell( file ); *eof = ftell( file );
} }
const char* err = ((res != 1) || ferror( file ) || feof( file )) ? "Couldn't get file size" : 0; const char* err = (ferror( file ) || feof( file )) ? "Couldn't get file size" : 0;
fclose( file ); fclose( file );
return err; return err;
} }