r1147 - in branches/unified-sdl/code: qcommon sys

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sun Sep 2 10:47:28 EDT 2007


Author: tma
Date: 2007-09-02 10:47:28 -0400 (Sun, 02 Sep 2007)
New Revision: 1147

Modified:
   branches/unified-sdl/code/qcommon/files.c
   branches/unified-sdl/code/sys/sys_main.c
   branches/unified-sdl/code/sys/sys_unix.c
   branches/unified-sdl/code/sys/sys_win32.c
Log:
* Fix to a subtle bug in the original FS code where an optimisation
  masked a failure case
* Fix a type in the original FS code fs_basepath -> fs_homepath
* Cache homePath value on all platforms
* Initialise installPath, binaryPath and homePath to { 0 }


Modified: branches/unified-sdl/code/qcommon/files.c
===================================================================
--- branches/unified-sdl/code/qcommon/files.c	2007-09-02 12:09:30 UTC (rev 1146)
+++ branches/unified-sdl/code/qcommon/files.c	2007-09-02 14:47:28 UTC (rev 1147)
@@ -649,8 +649,9 @@
 /*
 ===========
 FS_SV_FOpenFileRead
-search for a file somewhere below the home path, base path or cd path
-we search in that order, matching FS_SV_FOpenFileRead order
+
+Search for a file somewhere below the home path then base path
+in that order
 ===========
 */
 int FS_SV_FOpenFileRead( const char *filename, fileHandle_t *fp ) {
@@ -682,7 +683,7 @@
 	fsh[f].handleSync = qfalse;
 	if (!fsh[f].handleFiles.file.o)
 	{
-		// NOTE TTimo on non *nix systems, fs_homepath == fs_basepath, might want to avoid
+		// If fs_homepath == fs_basepath, don't bother
 		if (Q_stricmp(fs_homepath->string,fs_basepath->string))
 		{
 			// search basepath
@@ -696,11 +697,11 @@
 
 			fsh[f].handleFiles.file.o = fopen( ospath, "rb" );
 			fsh[f].handleSync = qfalse;
+		}
 
-			if ( !fsh[f].handleFiles.file.o )
-			{
-				f = 0;
-			}
+		if ( !fsh[f].handleFiles.file.o )
+		{
+			f = 0;
 		}
 	}
 
@@ -2723,7 +2724,7 @@
 	}
 	// fs_homepath is somewhat particular to *nix systems, only add if relevant
 	// NOTE: same filtering below for mods and basegame
-	if (fs_basepath->string[0] && Q_stricmp(fs_homepath->string,fs_basepath->string)) {
+	if (fs_homepath->string[0] && Q_stricmp(fs_homepath->string,fs_basepath->string)) {
 		FS_AddGameDirectory ( fs_homepath->string, gameName );
 	}
 

Modified: branches/unified-sdl/code/sys/sys_main.c
===================================================================
--- branches/unified-sdl/code/sys/sys_main.c	2007-09-02 12:09:30 UTC (rev 1146)
+++ branches/unified-sdl/code/sys/sys_main.c	2007-09-02 14:47:28 UTC (rev 1147)
@@ -43,8 +43,8 @@
 #include "../qcommon/q_shared.h"
 #include "../qcommon/qcommon.h"
 
-static char binaryPath[ MAX_OSPATH ];
-static char installPath[ MAX_OSPATH ];
+static char binaryPath[ MAX_OSPATH ] = { 0 };
+static char installPath[ MAX_OSPATH ] = { 0 };
 
 /*
 =================

Modified: branches/unified-sdl/code/sys/sys_unix.c
===================================================================
--- branches/unified-sdl/code/sys/sys_unix.c	2007-09-02 12:09:30 UTC (rev 1146)
+++ branches/unified-sdl/code/sys/sys_unix.c	2007-09-02 14:47:28 UTC (rev 1147)
@@ -34,9 +34,42 @@
 #include "../qcommon/qcommon.h"
 
 // Used to determine where to store user-specific files
-static char homePath[MAX_OSPATH];
+static char homePath[ MAX_OSPATH ] = { 0 };
 
 /*
+==================
+Sys_DefaultHomePath
+==================
+*/
+char *Sys_DefaultHomePath(void)
+{
+	char *p;
+
+	if( !*homePath )
+	{
+		if( ( p = getenv( "HOME" ) ) != NULL )
+		{
+			Q_strncpyz( homePath, p, sizeof( homePath ) );
+#ifdef MACOS_X
+			Q_strcat( homePath, sizeof( homePath ), "/Library/Application Support/Quake3" );
+#else
+			Q_strcat( homePath, sizeof( homePath ), "/.q3a" );
+#endif
+			if( mkdir( homePath, 0777 ) )
+			{
+				if( errno != EEXIST )
+				{
+					Sys_Error( "Unable to create directory \"%s\", error is %s(%d)\n",
+							homePath, strerror( errno ), errno );
+				}
+			}
+		}
+	}
+
+	return homePath;
+}
+
+/*
 ================
 Sys_Milliseconds
 ================
@@ -134,34 +167,6 @@
 
 /*
 ==================
-Sys_DefaultHomePath
-==================
-*/
-char *Sys_DefaultHomePath(void)
-{
-	char *p;
-
-	if (*homePath)
-		return homePath;
-
-	if ((p = getenv("HOME")) != NULL) {
-		Q_strncpyz(homePath, p, sizeof(homePath));
-#ifdef MACOS_X
-		Q_strcat(homePath, sizeof(homePath), "/Library/Application Support/Quake3");
-#else
-		Q_strcat(homePath, sizeof(homePath), "/.q3a");
-#endif
-		if (mkdir(homePath, 0777)) {
-			if (errno != EEXIST)
-				Sys_Error("Unable to create directory \"%s\", error is %s(%d)\n", homePath, strerror(errno), errno);
-		}
-		return homePath;
-	}
-	return ""; // assume current dir
-}
-
-/*
-==================
 Sys_ShowConsole
 ==================
 */

Modified: branches/unified-sdl/code/sys/sys_win32.c
===================================================================
--- branches/unified-sdl/code/sys/sys_win32.c	2007-09-02 12:09:30 UTC (rev 1146)
+++ branches/unified-sdl/code/sys/sys_win32.c	2007-09-02 14:47:28 UTC (rev 1147)
@@ -37,8 +37,61 @@
 #include <wincrypt.h>
 #include <shlobj.h>
 
+// Used to determine where to store user-specific files
+static char homePath[ MAX_OSPATH ] = { 0 };
+
 /*
 ================
+Sys_DefaultHomePath
+================
+*/
+char *Sys_DefaultHomePath( void )
+{
+	TCHAR szPath[MAX_PATH];
+	FARPROC qSHGetFolderPath;
+	HMODULE shfolder = LoadLibrary("shfolder.dll");
+	
+	if( !*homePath )
+	{
+		if(shfolder == NULL)
+		{
+			Com_Printf("Unable to load SHFolder.dll\n");
+			return NULL;
+		}
+
+		qSHGetFolderPath = GetProcAddress(shfolder, "SHGetFolderPathA");
+		if(qSHGetFolderPath == NULL)
+		{
+			Com_Printf("Unable to find SHGetFolderPath in SHFolder.dll\n");
+			FreeLibrary(shfolder);
+			return NULL;
+		}
+
+		if( !SUCCEEDED( qSHGetFolderPath( NULL, CSIDL_APPDATA,
+						NULL, 0, szPath ) ) )
+		{
+			Com_Printf("Unable to detect CSIDL_APPDATA\n");
+			FreeLibrary(shfolder);
+			return NULL;
+		}
+		Q_strncpyz( homePath, szPath, sizeof( homePath ) );
+		Q_strcat( homePath, sizeof( homePath ), "\\Quake3" );
+		FreeLibrary(shfolder);
+		if( !CreateDirectory( homePath, NULL ) )
+		{
+			if( GetLastError() != ERROR_ALREADY_EXISTS )
+			{
+				Com_Printf("Unable to create directory \"%s\"\n", path);
+				return NULL;
+			}
+		}
+	}
+
+	return homePath;
+}
+
+/*
+================
 Sys_Milliseconds
 ================
 */
@@ -131,52 +184,6 @@
 
 /*
 ================
-Sys_DefaultHomePath
-================
-*/
-char *Sys_DefaultHomePath( void )
-{
-	TCHAR szPath[MAX_PATH];
-	static char path[MAX_OSPATH];
-	FARPROC qSHGetFolderPath;
-	HMODULE shfolder = LoadLibrary("shfolder.dll");
-	
-	if(shfolder == NULL) {
-		Com_Printf("Unable to load SHFolder.dll\n");
-		return NULL;
-	}
-
-	qSHGetFolderPath = GetProcAddress(shfolder, "SHGetFolderPathA");
-	if(qSHGetFolderPath == NULL)
-	{
-		Com_Printf("Unable to find SHGetFolderPath in SHFolder.dll\n");
-		FreeLibrary(shfolder);
-		return NULL;
-	}
-
-	if( !SUCCEEDED( qSHGetFolderPath( NULL, CSIDL_APPDATA,
-		NULL, 0, szPath ) ) )
-	{
-		Com_Printf("Unable to detect CSIDL_APPDATA\n");
-		FreeLibrary(shfolder);
-		return NULL;
-	}
-	Q_strncpyz( path, szPath, sizeof(path) );
-	Q_strcat( path, sizeof(path), "\\Quake3" );
-	FreeLibrary(shfolder);
-	if( !CreateDirectory( path, NULL ) )
-	{
-		if( GetLastError() != ERROR_ALREADY_EXISTS )
-		{
-			Com_Printf("Unable to create directory \"%s\"\n", path);
-			return NULL;
-		}
-	}
-	return path;
-}
-
-/*
-================
 Sys_ShowConsole
 ================
 */




More information about the quake3-commits mailing list