5717 - Gamecode can open file "" for reading

This commit is contained in:
Zack Middleton 2013-02-15 21:08:47 -06:00
parent 92573270de
commit 2e45edb550
5 changed files with 38 additions and 9 deletions

View file

@ -82,6 +82,10 @@ int Sys_Milliseconds (void) {
return 0; return 0;
} }
FILE *Sys_FOpen(const char *ospath, const char *mode) {
return fopen( ospath, mode );
}
void Sys_Mkdir (char *path) { void Sys_Mkdir (char *path) {
} }

View file

@ -600,7 +600,7 @@ qboolean FS_FileInPathExists(const char *testpath)
{ {
FILE *filep; FILE *filep;
filep = fopen(testpath, "rb"); filep = Sys_FOpen(testpath, "rb");
if(filep) if(filep)
{ {
@ -675,7 +675,7 @@ fileHandle_t FS_SV_FOpenFileWrite( const char *filename ) {
} }
Com_DPrintf( "writing to: %s\n", ospath ); Com_DPrintf( "writing to: %s\n", ospath );
fsh[f].handleFiles.file.o = fopen( ospath, "wb" ); fsh[f].handleFiles.file.o = Sys_FOpen( ospath, "wb" );
Q_strncpyz( fsh[f].name, filename, sizeof( fsh[f].name ) ); Q_strncpyz( fsh[f].name, filename, sizeof( fsh[f].name ) );
@ -720,7 +720,7 @@ long FS_SV_FOpenFileRead(const char *filename, fileHandle_t *fp)
Com_Printf( "FS_SV_FOpenFileRead (fs_homepath): %s\n", ospath ); Com_Printf( "FS_SV_FOpenFileRead (fs_homepath): %s\n", ospath );
} }
fsh[f].handleFiles.file.o = fopen( ospath, "rb" ); fsh[f].handleFiles.file.o = Sys_FOpen( ospath, "rb" );
fsh[f].handleSync = qfalse; fsh[f].handleSync = qfalse;
if (!fsh[f].handleFiles.file.o) if (!fsh[f].handleFiles.file.o)
{ {
@ -736,7 +736,7 @@ long FS_SV_FOpenFileRead(const char *filename, fileHandle_t *fp)
Com_Printf( "FS_SV_FOpenFileRead (fs_basepath): %s\n", ospath ); Com_Printf( "FS_SV_FOpenFileRead (fs_basepath): %s\n", ospath );
} }
fsh[f].handleFiles.file.o = fopen( ospath, "rb" ); fsh[f].handleFiles.file.o = Sys_FOpen( ospath, "rb" );
fsh[f].handleSync = qfalse; fsh[f].handleSync = qfalse;
} }
@ -878,7 +878,7 @@ fileHandle_t FS_FOpenFileWrite( const char *filename ) {
// enabling the following line causes a recursive function call loop // enabling the following line causes a recursive function call loop
// when running with +set logfile 1 +set developer 1 // when running with +set logfile 1 +set developer 1
//Com_DPrintf( "writing to: %s\n", ospath ); //Com_DPrintf( "writing to: %s\n", ospath );
fsh[f].handleFiles.file.o = fopen( ospath, "wb" ); fsh[f].handleFiles.file.o = Sys_FOpen( ospath, "wb" );
Q_strncpyz( fsh[f].name, filename, sizeof( fsh[f].name ) ); Q_strncpyz( fsh[f].name, filename, sizeof( fsh[f].name ) );
@ -923,7 +923,7 @@ fileHandle_t FS_FOpenFileAppend( const char *filename ) {
return 0; return 0;
} }
fsh[f].handleFiles.file.o = fopen( ospath, "ab" ); fsh[f].handleFiles.file.o = Sys_FOpen( ospath, "ab" );
fsh[f].handleSync = qfalse; fsh[f].handleSync = qfalse;
if (!fsh[f].handleFiles.file.o) { if (!fsh[f].handleFiles.file.o) {
f = 0; f = 0;
@ -1162,7 +1162,7 @@ long FS_FOpenFileReadDir(const char *filename, searchpath_t *search, fileHandle_
dir = search->dir; dir = search->dir;
netpath = FS_BuildOSPath(dir->path, dir->gamedir, filename); netpath = FS_BuildOSPath(dir->path, dir->gamedir, filename);
filep = fopen (netpath, "rb"); filep = Sys_FOpen(netpath, "rb");
if(filep) if(filep)
{ {
@ -1296,7 +1296,7 @@ long FS_FOpenFileReadDir(const char *filename, searchpath_t *search, fileHandle_
dir = search->dir; dir = search->dir;
netpath = FS_BuildOSPath(dir->path, dir->gamedir, filename); netpath = FS_BuildOSPath(dir->path, dir->gamedir, filename);
filep = fopen(netpath, "rb"); filep = Sys_FOpen(netpath, "rb");
if (filep == NULL) if (filep == NULL)
{ {
@ -3312,7 +3312,7 @@ static void FS_Startup( const char *gameName )
#ifdef FS_MISSING #ifdef FS_MISSING
if (missingFiles == NULL) { if (missingFiles == NULL) {
missingFiles = fopen( "\\missing.txt", "ab" ); missingFiles = Sys_FOpen( "\\missing.txt", "ab" );
} }
#endif #endif
Com_Printf( "%d files in pk3 files\n", fs_packFiles ); Com_Printf( "%d files in pk3 files\n", fs_packFiles );

View file

@ -1107,6 +1107,7 @@ qboolean Sys_StringToAdr( const char *s, netadr_t *a, netadrtype_t family );
qboolean Sys_IsLANAddress (netadr_t adr); qboolean Sys_IsLANAddress (netadr_t adr);
void Sys_ShowIP(void); void Sys_ShowIP(void);
FILE *Sys_FOpen( const char *ospath, const char *mode );
qboolean Sys_Mkdir( const char *path ); qboolean Sys_Mkdir( const char *path );
FILE *Sys_Mkfifo( const char *ospath ); FILE *Sys_Mkfifo( const char *ospath );
char *Sys_Cwd( void ); char *Sys_Cwd( void );

View file

@ -192,6 +192,21 @@ const char *Sys_Dirname( char *path )
return dirname( path ); return dirname( path );
} }
/*
==============
Sys_FOpen
==============
*/
FILE *Sys_FOpen( const char *ospath, const char *mode ) {
struct stat buf;
// check if path exists and is a directory
if ( !stat( ospath, &buf ) && S_ISDIR( buf.st_mode ) )
return NULL;
return fopen( ospath, mode );
}
/* /*
================== ==================
Sys_Mkdir Sys_Mkdir

View file

@ -283,6 +283,15 @@ const char *Sys_Dirname( char *path )
return dir; return dir;
} }
/*
==============
Sys_FOpen
==============
*/
FILE *Sys_FOpen( const char *ospath, const char *mode ) {
return fopen( ospath, mode );
}
/* /*
============== ==============
Sys_Mkdir Sys_Mkdir