summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Middleton <zturtleman@gmail.com>2013-02-15 21:08:47 -0600
committerTim Angus <tim@ngus.net>2013-02-16 21:58:25 +0000
commit870d3661390e50de8d5d9444477c10c8d7929a77 (patch)
treeb5d9c96ae3a82fa7ee7aeafa7aeda48c3d525842
parent04c8f48d8363b80540a3ce057908413b4479c92b (diff)
5717 - Gamecode can open file "" for reading
-rw-r--r--src/null/null_main.c4
-rw-r--r--src/qcommon/files.c18
-rw-r--r--src/qcommon/qcommon.h1
-rw-r--r--src/sys/sys_unix.c15
-rw-r--r--src/sys/sys_win32.c9
5 files changed, 38 insertions, 9 deletions
diff --git a/src/null/null_main.c b/src/null/null_main.c
index ae77595c..c6abe925 100644
--- a/src/null/null_main.c
+++ b/src/null/null_main.c
@@ -83,6 +83,10 @@ int Sys_Milliseconds (void) {
return 0;
}
+FILE *Sys_FOpen(const char *ospath, const char *mode) {
+ return fopen( ospath, mode );
+}
+
void Sys_Mkdir (char *path) {
}
diff --git a/src/qcommon/files.c b/src/qcommon/files.c
index 6f790da3..6788ec82 100644
--- a/src/qcommon/files.c
+++ b/src/qcommon/files.c
@@ -578,7 +578,7 @@ qboolean FS_FileInPathExists(const char *testpath)
{
FILE *filep;
- filep = fopen(testpath, "rb");
+ filep = Sys_FOpen(testpath, "rb");
if(filep)
{
@@ -653,7 +653,7 @@ fileHandle_t FS_SV_FOpenFileWrite( const char *filename ) {
}
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 ) );
@@ -698,7 +698,7 @@ long FS_SV_FOpenFileRead(const char *filename, fileHandle_t *fp)
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;
if (!fsh[f].handleFiles.file.o)
{
@@ -714,7 +714,7 @@ long FS_SV_FOpenFileRead(const char *filename, fileHandle_t *fp)
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;
}
@@ -856,7 +856,7 @@ fileHandle_t FS_FOpenFileWrite( const char *filename ) {
// enabling the following line causes a recursive function call loop
// when running with +set logfile 1 +set developer 1
//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 ) );
@@ -901,7 +901,7 @@ fileHandle_t FS_FOpenFileAppend( const char *filename ) {
return 0;
}
- fsh[f].handleFiles.file.o = fopen( ospath, "ab" );
+ fsh[f].handleFiles.file.o = Sys_FOpen( ospath, "ab" );
fsh[f].handleSync = qfalse;
if (!fsh[f].handleFiles.file.o) {
f = 0;
@@ -1124,7 +1124,7 @@ long FS_FOpenFileReadDir(const char *filename, searchpath_t *search, fileHandle_
dir = search->dir;
netpath = FS_BuildOSPath(dir->path, dir->gamedir, filename);
- filep = fopen (netpath, "rb");
+ filep = Sys_FOpen(netpath, "rb");
if(filep)
{
@@ -1258,7 +1258,7 @@ long FS_FOpenFileReadDir(const char *filename, searchpath_t *search, fileHandle_
dir = search->dir;
netpath = FS_BuildOSPath(dir->path, dir->gamedir, filename);
- filep = fopen(netpath, "rb");
+ filep = Sys_FOpen(netpath, "rb");
if (filep == NULL)
{
@@ -3226,7 +3226,7 @@ static void FS_Startup( const char *gameName )
#ifdef FS_MISSING
if (missingFiles == NULL) {
- missingFiles = fopen( "\\missing.txt", "ab" );
+ missingFiles = Sys_FOpen( "\\missing.txt", "ab" );
}
#endif
Com_Printf( "%d files in pk3 files\n", fs_packFiles );
diff --git a/src/qcommon/qcommon.h b/src/qcommon/qcommon.h
index 430937c5..b61c27dc 100644
--- a/src/qcommon/qcommon.h
+++ b/src/qcommon/qcommon.h
@@ -1076,6 +1076,7 @@ qboolean Sys_StringToAdr( const char *s, netadr_t *a, netadrtype_t family );
qboolean Sys_IsLANAddress (netadr_t adr);
void Sys_ShowIP(void);
+FILE *Sys_FOpen( const char *ospath, const char *mode );
qboolean Sys_Mkdir( const char *path );
FILE *Sys_Mkfifo( const char *ospath );
char *Sys_Cwd( void );
diff --git a/src/sys/sys_unix.c b/src/sys/sys_unix.c
index b05cf855..7660edd1 100644
--- a/src/sys/sys_unix.c
+++ b/src/sys/sys_unix.c
@@ -186,6 +186,21 @@ const char *Sys_Dirname( char *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
==================
diff --git a/src/sys/sys_win32.c b/src/sys/sys_win32.c
index 45741a5d..fc5a399e 100644
--- a/src/sys/sys_win32.c
+++ b/src/sys/sys_win32.c
@@ -281,6 +281,15 @@ const char *Sys_Dirname( char *path )
/*
==============
+Sys_FOpen
+==============
+*/
+FILE *Sys_FOpen( const char *ospath, const char *mode ) {
+ return fopen( ospath, mode );
+}
+
+/*
+==============
Sys_Mkdir
==============
*/