*/
void PK3_CloseLibrary (void)
{
- if (!zlib_dll)
- return;
-
- Sys_UnloadLibrary (zlib_dll);
- zlib_dll = NULL;
+ Sys_UnloadLibrary (&zlib_dll);
}
qboolean PK3_OpenLibrary (void)
{
const char* dllname;
- const dllfunction_t *func;
// Already loaded?
if (zlib_dll)
dllname = "libz.so";
#endif
- // Initializations
- for (func = zlibfuncs; func && func->name != NULL; func++)
- *func->funcvariable = NULL;
-
// Load the DLL
- if (! (zlib_dll = Sys_LoadLibrary (dllname)))
+ if (! Sys_LoadLibrary (dllname, &zlib_dll, zlibfuncs))
{
- Con_Printf("Can't find %s. Compressed files support disabled\n", dllname);
+ Con_Printf ("Compressed files support disabled\n");
return false;
}
- // Get the function adresses
- for (func = zlibfuncs; func && func->name != NULL; func++)
- if (!(*func->funcvariable = (void *) Sys_GetProcAddress (zlib_dll, func->name)))
- {
- Con_Printf("missing function \"%s\" - broken Zlib library!\n", func->name);
- PK3_CloseLibrary ();
- return false;
- }
-
- Con_Printf("%s loaded. Compressed files support enabled\n", dllname);
+ Con_Printf ("Compressed files support enabled\n");
return true;
}
qboolean JPEG_OpenLibrary (void)
{
const char* dllname;
- const dllfunction_t *func;
// Already loaded?
if (jpeg_dll)
dllname = "libjpeg.so.62";
#endif
- // Initializations
- for (func = jpegfuncs; func && func->name != NULL; func++)
- *func->funcvariable = NULL;
-
// Load the DLL
- if (! (jpeg_dll = Sys_LoadLibrary (dllname)))
+ if (! Sys_LoadLibrary (dllname, &jpeg_dll, jpegfuncs))
{
- Con_DPrintf("Can't find %s. JPEG support disabled\n", dllname);
+ Con_Printf ("JPEG support disabled\n");
return false;
}
- // Get the function adresses
- for (func = jpegfuncs; func && func->name != NULL; func++)
- if (!(*func->funcvariable = (void *) Sys_GetProcAddress (jpeg_dll, func->name)))
- {
- Con_Printf("missing function \"%s\" - broken JPEG library!\n", func->name);
- JPEG_CloseLibrary ();
- return false;
- }
-
- Con_DPrintf("%s loaded. JPEG support enabled\n", dllname);
+ Con_Printf ("JPEG support enabled\n");
return true;
}
*/
void JPEG_CloseLibrary (void)
{
- if (!jpeg_dll)
- return;
-
- Sys_UnloadLibrary (jpeg_dll);
- jpeg_dll = NULL;
+ Sys_UnloadLibrary (&jpeg_dll);
}
qboolean OGG_OpenLibrary (void)
{
const char* dllname;
- const dllfunction_t *func;
// Already loaded?
if (vf_dll)
dllname = "libvorbisfile.so";
#endif
- // Initializations
- for (func = oggvorbisfuncs; func && func->name != NULL; func++)
- *func->funcvariable = NULL;
-
// Load the DLL
- if (! (vf_dll = Sys_LoadLibrary (dllname)))
+ if (! Sys_LoadLibrary (dllname, &vf_dll, oggvorbisfuncs))
{
- Con_DPrintf("Can't find %s. Ogg Vorbis support disabled\n", dllname);
+ Con_Printf ("Ogg Vorbis support disabled\n");
return false;
}
- // Get the function adresses
- for (func = oggvorbisfuncs; func && func->name != NULL; func++)
- if (!(*func->funcvariable = (void *) Sys_GetProcAddress (vf_dll, func->name)))
- {
- Con_Printf("missing function \"%s\" - broken Ogg Vorbis library!\n", func->name);
- OGG_CloseLibrary ();
- return false;
- }
-
- Con_DPrintf("%s loaded. Ogg Vorbis support enabled\n", dllname);
+ Con_Printf ("Ogg Vorbis support enabled\n");
return true;
}
*/
void OGG_CloseLibrary (void)
{
- if (!vf_dll)
- return;
-
- Sys_UnloadLibrary (vf_dll);
- vf_dll = NULL;
+ Sys_UnloadLibrary (&vf_dll);
}
}
dllfunction_t;
-dllhandle_t Sys_LoadLibrary (const char* name);
-void Sys_UnloadLibrary (dllhandle_t handle);
+qboolean Sys_LoadLibrary (const char* dllname, dllhandle_t* handle, const dllfunction_t *fcts);
+void Sys_UnloadLibrary (dllhandle_t* handle);
void* Sys_GetProcAddress (dllhandle_t handle, const char* name);
#include "quakedef.h"
-#include <time.h>
+# include <time.h>
#ifndef WIN32
-#include <unistd.h>
-#include <fcntl.h>
+# include <unistd.h>
+# include <fcntl.h>
+# include <dlfcn.h>
#endif
extern cvar_t timestamps;
===============================================================================
*/
-#ifndef WIN32
-#include <dlfcn.h>
-#endif
-
-dllhandle_t Sys_LoadLibrary (const char* name)
+qboolean Sys_LoadLibrary (const char* dllname, dllhandle_t* handle, const dllfunction_t *fcts)
{
+ const dllfunction_t *func;
+ dllhandle_t dllhandle;
+
+ if (handle == NULL)
+ return false;
+
+ // Initializations
+ for (func = fcts; func && func->name != NULL; func++)
+ *func->funcvariable = NULL;
+
+ // Load the DLL
#ifdef WIN32
- return LoadLibrary (name);
+ dllhandle = LoadLibrary (dllname);
#else
- return dlopen (name, RTLD_LAZY);
+ dllhandle = dlopen (dllname, RTLD_LAZY);
#endif
+ if (! dllhandle)
+ {
+ Con_Printf ("Can't load \"%s\".\n", dllname);
+ return false;
+ }
+
+ // Get the function adresses
+ for (func = fcts; func && func->name != NULL; func++)
+ if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
+ {
+ Con_Printf ("Missing function \"%s\" - broken library!\n", func->name);
+ Sys_UnloadLibrary (&dllhandle);
+ return false;
+ }
+
+ *handle = dllhandle;
+ Con_DPrintf("\"%s\" loaded.\n", dllname);
+ return true;
}
-void Sys_UnloadLibrary (dllhandle_t handle)
+void Sys_UnloadLibrary (dllhandle_t* handle)
{
+ if (handle == NULL || *handle == NULL)
+ return;
+
#ifdef WIN32
- FreeLibrary (handle);
+ FreeLibrary (*handle);
#else
- dlclose (handle);
+ dlclose (*handle);
#endif
+
+ *handle = NULL;
}
void* Sys_GetProcAddress (dllhandle_t handle, const char* name)