/* ============= Sys_LoadImage ============= */ void Sys_LoadImage( ){ void *dl; char *error; char module[MAX_OSPATH]; Com_sprintf(module, sizeof(module), "%s/%s", Sys_BinaryPath(), COD4_DLL); if(!Sys_LoadImagePrepareFile( module )) { printf("An error has occurred. Exiting...\n"); _exit(1); } dl = dlopen(module, RTLD_LAZY); if(dl == NULL) { error = dlerror(); printf("Failed to load required module: %s Error: %s\n", module, error); _exit(1); } /* No retrieving of symbols where none are :( */ if(!Sys_PatchImage()) { printf("Failed to patch module: %s\n", module); _exit(1); } }
void *Sys_LoadDll(const char *name, qboolean useSystemLib) { void *dllhandle = NULL; if(useSystemLib) Com_Printf("Trying to load \"%s\"...\n", name); if(!useSystemLib || !(dllhandle = Sys_LoadLibrary(name))) { const char *topDir; char libPath[MAX_OSPATH]; topDir = Sys_BinaryPath(); if(!*topDir) topDir = "."; Com_Printf("Trying to load \"%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("Trying to load \"%s\" from \"%s\"...\n", name, basePath); Com_sprintf(libPath, sizeof(libPath), "%s%c%s", basePath, PATH_SEP, name); dllhandle = Sys_LoadLibrary(libPath); } if(!dllhandle) { const char *cdPath = Cvar_VariableString("fs_cdpath"); if(!basePath || !*basePath) basePath = "."; if(FS_FilenameCompare(topDir, cdPath)) { Com_Printf("Trying to load \"%s\" from \"%s\"...\n", name, cdPath); Com_sprintf(libPath, sizeof(libPath), "%s%c%s", cdPath, PATH_SEP, name); dllhandle = Sys_LoadLibrary(libPath); } if(!dllhandle) { Com_Printf("Loading \"%s\" failed\n", name); } } } } return 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, qboolean useSystemLib ) { void *dllhandle = NULL; // Don't load any DLLs that end with the pk3 extension if ( COM_CompareExtension( name, ".pk3" ) ) { Com_Printf( S_COLOR_YELLOW "WARNING: Rejecting DLL named \"%s\"", name ); return NULL; } if ( useSystemLib ) { Com_Printf( "Trying to load \"%s\"...\n", name ); dllhandle = Sys_LoadLibrary( name ); if ( dllhandle ) return dllhandle; Com_Printf( "%s(%s) failed: \"%s\"\n", __FUNCTION__, name, Sys_LibraryError() ); } const char *binarypath = Sys_BinaryPath(); const char *basepath = Cvar_VariableString( "fs_basepath" ); if ( !*binarypath ) binarypath = "."; const char *searchPaths[] = { binarypath, basepath, }; const size_t numPaths = ARRAY_LEN( searchPaths ); for ( size_t i = 0; i < numPaths; i++ ) { const char *libDir = searchPaths[i]; if ( !libDir[0] ) continue; Com_Printf( "Trying to load \"%s\" from \"%s\"...\n", name, libDir ); char *fn = va( "%s%c%s", libDir, PATH_SEP, name ); dllhandle = Sys_LoadLibrary( fn ); if ( dllhandle ) return dllhandle; Com_Printf( "%s(%s) failed: \"%s\"\n", __FUNCTION__, fn, Sys_LibraryError() ); } return NULL; }
/* ================= Sys_LoadDll First try to load library name from system library path, from executable path, then fs_basepath. ================= */ void *Sys_LoadDll( const char *name, qboolean useSystemLib ) { void *dllhandle = NULL; if ( useSystemLib ) { Com_Printf( "Trying to load \"%s\"...\n", name ); dllhandle = Sys_LoadLibrary( name ); if ( dllhandle ) return dllhandle; Com_Printf( "%s(%s) failed: \"%s\"\n", __FUNCTION__, name, Sys_LibraryError() ); } const char *binarypath = Sys_BinaryPath(); const char *basepath = Cvar_VariableString( "fs_basepath" ); if ( !*binarypath ) binarypath = "."; const char *searchPaths[] = { binarypath, basepath, }; const size_t numPaths = ARRAY_LEN( searchPaths ); for ( size_t i = 0; i < numPaths; i++ ) { const char *libDir = searchPaths[i]; if ( !libDir[0] ) continue; Com_Printf( "Trying to load \"%s\" from \"%s\"...\n", name, libDir ); char *fn = va( "%s%c%s", libDir, PATH_SEP, name ); dllhandle = Sys_LoadLibrary( fn ); if ( dllhandle ) return dllhandle; Com_Printf( "%s(%s) failed: \"%s\"\n", __FUNCTION__, fn, Sys_LibraryError() ); } return NULL; }
/* * First try to load library name from system library path, * from executable path, then fs_basepath. */ void * Sys_LoadDll(const char *name, qbool useSystemLib) { void *dllhandle; if(useSystemLib) comprintf("Trying to load \"%s\"...\n", name); if(!useSystemLib || !(dllhandle = Sys_LoadLibrary(name))){ const char *topDir; char libPath[MAX_OSPATH]; topDir = Sys_BinaryPath(); if(!*topDir) topDir = "."; comprintf("Trying to load \"%s\" from \"%s\"...\n", name, topDir); Q_sprintf(libPath, sizeof(libPath), "%s%c%s", topDir, PATH_SEP, name); if(!(dllhandle = Sys_LoadLibrary(libPath))){ const char *basePath = cvargetstr("fs_basepath"); if(!basePath || !*basePath) basePath = "."; if(fscomparefname(topDir, basePath)){ comprintf("Trying to load \"%s\" from \"%s\"...\n", name, basePath); Q_sprintf(libPath, sizeof(libPath), "%s%c%s", basePath, PATH_SEP, name); dllhandle = Sys_LoadLibrary(libPath); } if(!dllhandle) comprintf("Loading \"%s\" failed\n", name); } } return dllhandle; }
/* ================= Sys_DefaultAppPath ================= */ char *Sys_DefaultAppPath(void) { return Sys_BinaryPath(); }
char* sysgetdefaultapppath(void) { return Sys_BinaryPath(); }
void *Sys_LoadDll(const char *name, qboolean useSystemLib) { void *dllhandle = NULL; if(!Sys_DllExtension(name)) { Com_Printf("Refusing to attempt to load library \"%s\": Extension not allowed.\n", name); return NULL; } if(useSystemLib) { Com_Printf("Trying to load \"%s\"...\n", name); dllhandle = Sys_LoadLibrary(name); } if(!dllhandle) { const char *topDir; char libPath[MAX_OSPATH]; int len; topDir = Sys_BinaryPath(); if(!*topDir) topDir = "."; len = Com_sprintf(libPath, sizeof(libPath), "%s%c%s", topDir, PATH_SEP, name); if(len < sizeof(libPath)) { Com_Printf("Trying to load \"%s\" from \"%s\"...\n", name, topDir); dllhandle = Sys_LoadLibrary(libPath); } else { Com_Printf("Skipping trying to load \"%s\" from \"%s\", file name is too long.\n", name, topDir); } if(!dllhandle) { const char *basePath = Cvar_VariableString("fs_basepath"); if(!basePath || !*basePath) basePath = "."; if(FS_FilenameCompare(topDir, basePath)) { len = Com_sprintf(libPath, sizeof(libPath), "%s%c%s", basePath, PATH_SEP, name); if(len < sizeof(libPath)) { Com_Printf("Trying to load \"%s\" from \"%s\"...\n", name, basePath); dllhandle = Sys_LoadLibrary(libPath); } else { Com_Printf("Skipping trying to load \"%s\" from \"%s\", file name is too long.\n", name, basePath); } } if(!dllhandle) Com_Printf("Loading \"%s\" failed\n", name); } } return dllhandle; }