summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThilo Schulz <arny@ats.s.bawue.de>2011-07-29 20:18:37 +0000
committerTim Angus <tim@ngus.net>2013-01-10 22:55:15 +0000
commit64280de4fc1621c1280407acc9e1043043319ca0 (patch)
treed9e7cb6b88abbcc1ecef045b090a9e1fc0eba696
parent7f1fee44e5cd45cff829951757f5c6460c06cbe8 (diff)
Change DLL search path order for external libraries that are linked at runtime, like libcurl or libopenal to: * system library paths * executable path * fs_basepath
-rw-r--r--src/client/cl_curl.c25
-rw-r--r--src/client/qal.c17
-rw-r--r--src/qcommon/qcommon.h2
-rw-r--r--src/qcommon/vm.c2
-rw-r--r--src/sys/sys_loadlib.h2
-rw-r--r--src/sys/sys_main.c57
6 files changed, 65 insertions, 40 deletions
diff --git a/src/client/cl_curl.c b/src/client/cl_curl.c
index 63958e38..f8f6580d 100644
--- a/src/client/cl_curl.c
+++ b/src/client/cl_curl.c
@@ -95,30 +95,19 @@ qboolean CL_cURL_Init()
Com_Printf("Loading \"%s\"...", cl_cURLLib->string);
- if( (cURLLib = Sys_LoadLibrary(cl_cURLLib->string)) == 0 )
+ if(!(cURLLib = Sys_LoadDll(cl_cURLLib->string)))
{
#ifdef _WIN32
return qfalse;
+
+#elsif ALTERNATE_CURL_LIB
+ // On some linux distributions there is no libcurl.so.3, but only libcurl.so.4. That one works too.
+ if(!(cURLLib = Sys_LoadDll(ALTERNATE_CURL_LIB)))
+ return qfalse;
#else
- char fn[1024];
-
- Q_strncpyz( fn, Sys_Cwd( ), sizeof( fn ) );
- strncat(fn, "/", sizeof(fn)-strlen(fn)-1);
- strncat(fn, cl_cURLLib->string, sizeof(fn)-strlen(fn)-1);
-
- if((cURLLib = Sys_LoadLibrary(fn)) == 0)
- {
-#ifdef ALTERNATE_CURL_LIB
- // On some linux distributions there is no libcurl.so.3, but only libcurl.so.4. That one works too.
- if( (cURLLib = Sys_LoadLibrary(ALTERNATE_CURL_LIB)) == 0 )
- {
- return qfalse;
- }
-#else
+
return qfalse;
#endif
- }
-#endif /* _WIN32 */
}
clc.cURLEnabled = qtrue;
diff --git a/src/client/qal.c b/src/client/qal.c
index 57db8ed8..68f19b72 100644
--- a/src/client/qal.c
+++ b/src/client/qal.c
@@ -145,23 +145,8 @@ qboolean QAL_Init(const char *libname)
if(OpenALLib)
return qtrue;
- Com_Printf( "Loading \"%s\"...\n", libname);
- if( (OpenALLib = Sys_LoadLibrary(libname)) == 0 )
- {
-#ifdef _WIN32
+ if(!(OpenALLib = Sys_LoadDll(libname)))
return qfalse;
-#else
- char fn[1024];
- Q_strncpyz( fn, Sys_Cwd( ), sizeof( fn ) );
- strncat(fn, "/", sizeof(fn) - strlen(fn) - 1);
- strncat(fn, libname, sizeof(fn) - strlen(fn) - 1);
-
- if( (OpenALLib = Sys_LoadLibrary(fn)) == 0 )
- {
- return qfalse;
- }
-#endif
- }
alinit_fail = qfalse;
diff --git a/src/qcommon/qcommon.h b/src/qcommon/qcommon.h
index 275fb4a5..980d0cfb 100644
--- a/src/qcommon/qcommon.h
+++ b/src/qcommon/qcommon.h
@@ -1042,7 +1042,7 @@ typedef enum {
void Sys_Init (void);
// general development dll loading for virtual machine testing
-void * QDECL Sys_LoadDll( const char *name, intptr_t (QDECL **entryPoint)(int, ...),
+void * QDECL Sys_LoadQVMDll( const char *name, intptr_t (QDECL **entryPoint)(int, ...),
intptr_t (QDECL *systemcalls)(intptr_t, ...) );
void Sys_UnloadDll( void *dllHandle );
diff --git a/src/qcommon/vm.c b/src/qcommon/vm.c
index 2fdb77f0..536b2ff7 100644
--- a/src/qcommon/vm.c
+++ b/src/qcommon/vm.c
@@ -580,7 +580,7 @@ vm_t *VM_Create( const char *module, intptr_t (*systemCalls)(intptr_t *),
{
Com_Printf("Try loading dll file %s\n", filename);
- vm->dllHandle = Sys_LoadDll(filename, &vm->entryPoint, VM_DllSyscall);
+ vm->dllHandle = Sys_LoadQVMDll(filename, &vm->entryPoint, VM_DllSyscall);
if(vm->dllHandle)
{
diff --git a/src/sys/sys_loadlib.h b/src/sys/sys_loadlib.h
index 02bb7627..513b7d6c 100644
--- a/src/sys/sys_loadlib.h
+++ b/src/sys/sys_loadlib.h
@@ -48,3 +48,5 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# define Sys_LoadFunction(h,fn) SDL_LoadFunction(h,fn)
# define Sys_LibraryError() SDL_GetError()
#endif
+
+void * QDECL Sys_LoadDll(const char *name);
diff --git a/src/sys/sys_main.c b/src/sys/sys_main.c
index 9e4d6863..1ee40897 100644
--- a/src/sys/sys_main.c
+++ b/src/sys/sys_main.c
@@ -413,10 +413,59 @@ void Sys_UnloadDll( void *dllHandle )
=================
Sys_LoadDll
+First try to load library name from system library path,
+from executable path, then fs_basepath.
+=================
+*/
+
+void *Sys_LoadDll(const char *name)
+{
+ void *dllhandle;
+
+ Com_Printf("Try loading \"%s\"...\n", name);
+ if(!(dllhandle = Sys_LoadLibrary(name)))
+ {
+ const char *topDir;
+ char libPath[MAX_OSPATH];
+
+ topDir = Sys_BinaryPath();
+
+ if(!*topDir)
+ topDir = ".";
+
+ Com_Printf("Try loading \"%s\" from \"%s\"...\n", name, topDir);
+ Com_sprintf(libPath, sizeof(libPath), "%s%c%s", topDir, PATH_SEP, name);
+
+ if(!(dllhandle = Sys_LoadLibrary(libPath)))
+ {
+ const char *basePath = Cvar_VariableString("fs_basepath");
+
+ if(!basePath || !*basePath)
+ basePath = ".";
+
+ if(FS_FilenameCompare(topDir, basePath))
+ {
+ Com_Printf("Try loading \"%s\" from \"%s\"...\n", name, basePath);
+ Com_sprintf(libPath, sizeof(libPath), "%s%c%s", basePath, PATH_SEP, name);
+ dllhandle = Sys_LoadLibrary(libPath);
+ }
+
+ if(!dllhandle)
+ Com_Printf("Loading \"%s\" failed\n", name);
+ }
+ }
+
+ return dllhandle;
+}
+
+/*
+=================
+Sys_LoadQVMDll
+
Used to load a development dll instead of a virtual machine
=================
*/
-void *Sys_LoadDll(const char *name,
+void *Sys_LoadQVMDll(const char *name,
intptr_t (QDECL **entryPoint)(int, ...),
intptr_t (*systemcalls)(intptr_t, ...))
{
@@ -430,7 +479,7 @@ void *Sys_LoadDll(const char *name,
if(!libHandle)
{
- Com_Printf("Sys_LoadDll(%s) failed:\n\"%s\"\n", name, Sys_LibraryError());
+ Com_Printf("Sys_LoadQVMDll(%s) failed:\n\"%s\"\n", name, Sys_LibraryError());
return NULL;
}
@@ -439,13 +488,13 @@ void *Sys_LoadDll(const char *name,
if ( !*entryPoint || !dllEntry )
{
- Com_Printf ( "Sys_LoadDll(%s) failed to find vmMain function:\n\"%s\" !\n", name, Sys_LibraryError( ) );
+ Com_Printf ( "Sys_LoadQVMDll(%s) failed to find vmMain function:\n\"%s\" !\n", name, Sys_LibraryError( ) );
Sys_UnloadLibrary(libHandle);
return NULL;
}
- Com_Printf ( "Sys_LoadDll(%s) found vmMain function at %p\n", name, *entryPoint );
+ Com_Printf ( "Sys_LoadQVMDll(%s) found vmMain function at %p\n", name, *entryPoint );
dllEntry( systemcalls );
return libHandle;