[quake3-commits] r1856 - in trunk/code: qcommon sys
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Fri Feb 4 12:47:58 EST 2011
Author: thilo
Date: 2011-02-04 12:47:57 -0500 (Fri, 04 Feb 2011)
New Revision: 1856
Modified:
trunk/code/qcommon/files.c
trunk/code/qcommon/qcommon.h
trunk/code/sys/sys_main.c
Log:
Patch by Simon McVittie to improve dynamic library loading (#4700)
Modified: trunk/code/qcommon/files.c
===================================================================
--- trunk/code/qcommon/files.c 2011-02-04 17:31:12 UTC (rev 1855)
+++ trunk/code/qcommon/files.c 2011-02-04 17:47:57 UTC (rev 1856)
@@ -1220,6 +1220,32 @@
}
+char *FS_FindDll( const char *filename ) {
+ searchpath_t *search;
+ directory_t *dir;
+
+ if ( !fs_searchpaths ) {
+ Com_Error( ERR_FATAL, "Filesystem call made without initialization\n" );
+ }
+
+ for ( search = fs_searchpaths ; search ; search = search->next ) {
+ if ( search->dir ) {
+ FILE *f;
+ char *netpath;
+
+ dir = search->dir;
+ netpath = FS_BuildOSPath( dir->path, dir->gamedir, filename );
+ f = fopen( netpath, "rb" );
+ if (f) {
+ fclose( f );
+ return netpath;
+ }
+ }
+ }
+
+ return NULL;
+}
+
/*
=================
FS_Read
Modified: trunk/code/qcommon/qcommon.h
===================================================================
--- trunk/code/qcommon/qcommon.h 2011-02-04 17:31:12 UTC (rev 1855)
+++ trunk/code/qcommon/qcommon.h 2011-02-04 17:47:57 UTC (rev 1856)
@@ -606,6 +606,9 @@
qboolean FS_FileExists( const char *file );
qboolean FS_CreatePath (char *OSPath);
+
+char *FS_FindDll( const char *filename );
+
char *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
qboolean FS_CompareZipChecksum(const char *zipfile);
Modified: trunk/code/sys/sys_main.c
===================================================================
--- trunk/code/sys/sys_main.c 2011-02-04 17:31:12 UTC (rev 1855)
+++ trunk/code/sys/sys_main.c 2011-02-04 17:47:57 UTC (rev 1856)
@@ -407,34 +407,6 @@
/*
=================
-Sys_TryLibraryLoad
-=================
-*/
-static void* Sys_TryLibraryLoad(const char* base, const char* gamedir, const char* fname, char* fqpath )
-{
- void* libHandle;
- char* fn;
-
- *fqpath = 0;
-
- fn = FS_BuildOSPath( base, gamedir, fname );
- Com_Printf( "Sys_LoadDll(%s)... \n", fn );
-
- libHandle = Sys_LoadLibrary(fn);
-
- if(!libHandle) {
- Com_Printf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, Sys_LibraryError() );
- return NULL;
- }
-
- Com_Printf ( "Sys_LoadDll(%s): succeeded ...\n", fn );
- Q_strncpyz ( fqpath , fn , MAX_QPATH ) ;
-
- return libHandle;
-}
-
-/*
-=================
Sys_LoadDll
Used to load a development dll instead of a virtual machine
@@ -449,26 +421,24 @@
void *libHandle;
void (*dllEntry)( intptr_t (*syscallptr)(intptr_t, ...) );
char fname[MAX_OSPATH];
- char *basepath;
- char *homepath;
- char *gamedir;
+ char *netpath;
assert( name );
Q_snprintf (fname, sizeof(fname), "%s" ARCH_STRING DLL_EXT, name);
- // TODO: use fs_searchpaths from files.c
- basepath = Cvar_VariableString( "fs_basepath" );
- homepath = Cvar_VariableString( "fs_homepath" );
- gamedir = Cvar_VariableString( "fs_game" );
+ netpath = FS_FindDll(fname);
- libHandle = Sys_TryLibraryLoad(homepath, gamedir, fname, fqpath);
+ if(!netpath) {
+ Com_Printf( "Sys_LoadDll(%s) could not find it\n", fname );
+ return NULL;
+ }
- if(!libHandle && basepath)
- libHandle = Sys_TryLibraryLoad(basepath, gamedir, fname, fqpath);
+ Com_Printf( "Loading DLL file: %s\n", netpath);
+ libHandle = Sys_LoadLibrary(netpath);
if(!libHandle) {
- Com_Printf ( "Sys_LoadDll(%s) failed to load library\n", name );
+ Com_Printf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", netpath, Sys_LibraryError() );
return NULL;
}
More information about the quake3-commits
mailing list