the PK3 and Vorbis supports on NetBSD)
- Added a check for absolute paths in FS_CheckNastyPath
- Moved "COM_Shutdown" after "Log_Close" in the shutdown process to make
sure the FS code is still active when we close the log file
- Factorized some code in the FS module
- Made the "listdirectory" parameter "const"
- Fixed a warning in "prvm_cmds.c" when compiling with GCC
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4909
d7cf8633-e32d-0410-b094-
e92efae38249
stringlist_t *stringlistappend(stringlist_t *current, char *text);
void stringlistfree(stringlist_t *current);
stringlist_t *stringlistsort(stringlist_t *start);
stringlist_t *stringlistappend(stringlist_t *current, char *text);
void stringlistfree(stringlist_t *current);
stringlist_t *stringlistsort(stringlist_t *start);
-stringlist_t *listdirectory(char *path);
+stringlist_t *listdirectory(const char *path);
void freedirectory(stringlist_t *list);
char *SearchInfostring(const char *infostring, const char *key);
void freedirectory(stringlist_t *list);
char *SearchInfostring(const char *infostring, const char *key);
// operating system specific code
#ifdef WIN32
#include <io.h>
// operating system specific code
#ifdef WIN32
#include <io.h>
-stringlist_t *listdirectory(char *path)
+stringlist_t *listdirectory(const char *path)
{
char pattern[4096], *c;
struct _finddata_t n_file;
{
char pattern[4096], *c;
struct _finddata_t n_file;
}
#else
#include <dirent.h>
}
#else
#include <dirent.h>
-stringlist_t *listdirectory(char *path)
+stringlist_t *listdirectory(const char *path)
{
DIR *dir;
struct dirent *ent;
{
DIR *dir;
struct dirent *ent;
*/
qboolean PK3_OpenLibrary (void)
{
*/
qboolean PK3_OpenLibrary (void)
{
- const char* dllname;
-
- // Already loaded?
- if (zlib_dll)
- return true;
-
+ const char* dllnames [] =
+ {
- dllname = "libz.dylib";
+ "libz.so.1",
+ "libz.so",
+ NULL
+ };
+
+ // Already loaded?
+ if (zlib_dll)
+ return true;
- if (! Sys_LoadLibrary (dllname, &zlib_dll, zlibfuncs))
+ if (! Sys_LoadLibrary (dllnames, &zlib_dll, zlibfuncs))
{
Con_Printf ("Compressed files support disabled\n");
return false;
{
Con_Printf ("Compressed files support disabled\n");
return false;
then loads and adds pak1.pak pak2.pak ...
================
*/
then loads and adds pak1.pak pak2.pak ...
================
*/
-void FS_AddGameDirectory (char *dir)
+void FS_AddGameDirectory (const char *dir)
{
stringlist_t *list, *current;
searchpath_t *search;
{
stringlist_t *list, *current;
searchpath_t *search;
-FS_AddHomeAsGameDirectory
-
-Use ~/.games/darkplaces/dir as fs_gamedir
-void FS_AddHomeAsGameDirectory (const char *dir)
+void FS_AddGameHierarchy (const char *dir)
-#ifndef _WIN32
- char *homedir=getenv("HOME");
- char gdir[MAX_OSPATH];
- if(homedir)
- {
- int len = snprintf(gdir,sizeof(gdir),"%s/.darkplaces/%s/", homedir, dir);
- Con_Printf("using %s for writing\n",gdir);
- FS_CreatePath (gdir);
- if ((len > 0) && (len < sizeof(gdir)) && (gdir[len-1] == '/'))
- gdir[len-1] = 0;
+ strlcpy (com_modname, dir, sizeof (com_modname));
- strncpy(fs_gamedir,gdir,sizeof(fs_gamedir)-1);
- fs_gamedir[sizeof(fs_gamedir)-1] = 0;
-
- FS_AddGameDirectory (gdir);
- }
-#endif
+ // Add the common game directory
+ FS_AddGameDirectory (va("%s/%s", fs_basedir, dir));
+
+ // Add the personal game directory
+ homedir = getenv ("HOME");
+ if (homedir != NULL && homedir[0] != '\0')
+ FS_AddGameDirectory (va("%s/.darkplaces/%s", homedir, dir));
}
// start up with GAMENAME by default (id1)
}
// start up with GAMENAME by default (id1)
- strlcpy (com_modname, GAMENAME, sizeof (com_modname));
- FS_AddGameDirectory (va("%s/"GAMENAME, fs_basedir));
- FS_AddHomeAsGameDirectory(GAMENAME);
+ FS_AddGameHierarchy (GAMENAME);
Cvar_SetQuick (&scr_screenshot_name, gamescreenshotname);
// add the game-specific path, if any
if (gamedirname[0])
{
fs_modified = true;
Cvar_SetQuick (&scr_screenshot_name, gamescreenshotname);
// add the game-specific path, if any
if (gamedirname[0])
{
fs_modified = true;
- strlcpy (com_modname, gamedirname, sizeof (com_modname));
- FS_AddGameDirectory (va("%s/%s", fs_basedir, gamedirname));
- FS_AddHomeAsGameDirectory(gamedirname);
+ FS_AddGameHierarchy (gamedirname);
{
i++;
fs_modified = true;
{
i++;
fs_modified = true;
- strlcpy (com_modname, com_argv[i], sizeof (com_modname));
- FS_AddGameDirectory (va("%s/%s", fs_basedir, com_argv[i]));
- FS_AddHomeAsGameDirectory(com_argv[i]);
+ FS_AddGameHierarchy (com_argv[i]);
Cvar_SetQuick (&scr_screenshot_name, com_modname);
}
}
Cvar_SetQuick (&scr_screenshot_name, com_modname);
}
}
return 1; // non-portable attempt to go to parent directory
// all: don't allow going to current directory (./) or parent directory (../ or /../)
if (strstr(path, "./"))
return 1; // non-portable attempt to go to parent directory
// all: don't allow going to current directory (./) or parent directory (../ or /../)
if (strstr(path, "./"))
- return 2; // attempt to go to parent directory
+ return 2; // attempt to go outside the game directory
+ // Windows and UNIXes: don't allow absolute paths
+ if (path[0] == '/')
+ return 2; // attempt to go outside the game directory
// after all these checks we're pretty sure it's a / separated filename
// and won't do much if any harm
return false;
// after all these checks we're pretty sure it's a / separated filename
// and won't do much if any harm
return false;
S_Terminate ();
NetConn_Shutdown ();
PR_Shutdown ();
S_Terminate ();
NetConn_Shutdown ();
PR_Shutdown ();
Cbuf_Shutdown ();
if (cls.state != ca_dedicated)
Cbuf_Shutdown ();
if (cls.state != ca_dedicated)
CL_Shutdown();
Sys_Shutdown();
Log_Close ();
CL_Shutdown();
Sys_Shutdown();
Log_Close ();
*/
qboolean JPEG_OpenLibrary (void)
{
*/
qboolean JPEG_OpenLibrary (void)
{
- const char* dllname;
-
- // Already loaded?
- if (jpeg_dll)
- return true;
-
-// TODO: make Sys_LoadLibrary support multiple names
+ const char* dllnames [] =
+ {
- dllname = "libjpeg.dll";
-#elif defined(__FreeBSD__)
- dllname = "libjpeg.so";
- dllname = "libjpeg.62.dylib";
- dllname = "libjpeg.so.62";
+ "libjpeg.so.62",
+ "libjpeg.so",
+ NULL
+ };
+
+ // Already loaded?
+ if (jpeg_dll)
+ return true;
- if (! Sys_LoadLibrary (dllname, &jpeg_dll, jpegfuncs))
+ if (! Sys_LoadLibrary (dllnames, &jpeg_dll, jpegfuncs))
{
Con_Printf ("JPEG support disabled\n");
return false;
{
Con_Printf ("JPEG support disabled\n");
return false;
for( ; *str; *out++ = *str++ );
// now jump over the old contents
for( ; *in ; in++ )
for( ; *str; *out++ = *str++ );
// now jump over the old contents
for( ; *in ; in++ )
- if( *in == '\'' || *in == '\\' && !*++in )
+ if( *in == '\'' || (*in == '\\' && !*++in) )
*/
qboolean OGG_OpenLibrary (void)
{
*/
qboolean OGG_OpenLibrary (void)
{
- const char *dllname_vo, *dllname_vf;
+ const char* dllnames_vo [] =
+ {
+#ifdef WIN32
+ "vorbis.dll",
+#elif defined(MACOSX)
+ "libvorbis.dylib",
+#else
+ "libvorbis.so.0",
+ "libvorbis.so",
+#endif
+ NULL
+ };
+ const char* dllnames_vf [] =
+ {
+#ifdef WIN32
+ "vorbisfile.dll",
+#elif defined(MACOSX)
+ "libvorbisfile.dylib",
+#else
+ "libvorbisfile.so.3",
+ "libvorbisfile.so",
+#endif
+ NULL
+ };
// Already loaded?
if (vf_dll)
// Already loaded?
if (vf_dll)
if (COM_CheckParm("-novorbis"))
return false;
if (COM_CheckParm("-novorbis"))
return false;
-#ifdef WIN32
- dllname_vo = "vorbis.dll";
- dllname_vf = "vorbisfile.dll";
-#elif defined(MACOSX)
- dllname_vo = "libvorbis.dylib";
- dllname_vf = "libvorbisfile.dylib";
-#else
- dllname_vo = "libvorbis.so.0";
- dllname_vf = "libvorbisfile.so.3";
-#endif
-
// Load the DLLs
// We need to load both by hand because some OSes seem to not load
// the vorbis DLL automatically when loading the VorbisFile DLL
// Load the DLLs
// We need to load both by hand because some OSes seem to not load
// the vorbis DLL automatically when loading the VorbisFile DLL
- if (! Sys_LoadLibrary (dllname_vo, &vo_dll, NULL) ||
- ! Sys_LoadLibrary (dllname_vf, &vf_dll, oggvorbisfuncs))
+ if (! Sys_LoadLibrary (dllnames_vo, &vo_dll, NULL) ||
+ ! Sys_LoadLibrary (dllnames_vf, &vf_dll, oggvorbisfuncs))
{
Sys_UnloadLibrary (&vo_dll);
Con_Printf ("Ogg Vorbis support disabled\n");
{
Sys_UnloadLibrary (&vo_dll);
Con_Printf ("Ogg Vorbis support disabled\n");
-qboolean Sys_LoadLibrary (const char* dllname, dllhandle_t* handle, const dllfunction_t *fcts);
+// "dllnames" is an NULL terminated array of possible names for the DLL you want to load
+qboolean Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts);
void Sys_UnloadLibrary (dllhandle_t* handle);
void* Sys_GetProcAddress (dllhandle_t handle, const char* name);
void Sys_UnloadLibrary (dllhandle_t* handle);
void* Sys_GetProcAddress (dllhandle_t handle, const char* name);
===============================================================================
*/
===============================================================================
*/
-qboolean Sys_LoadLibrary (const char* dllname, dllhandle_t* handle, const dllfunction_t *fcts)
+qboolean Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts)
{
const dllfunction_t *func;
{
const dllfunction_t *func;
+ dllhandle_t dllhandle = 0;
+ unsigned int i;
if (handle == NULL)
return false;
if (handle == NULL)
return false;
for (func = fcts; func && func->name != NULL; func++)
*func->funcvariable = NULL;
for (func = fcts; func && func->name != NULL; func++)
*func->funcvariable = NULL;
+ // Try every possible name
+ for (i = 0; dllnames[i] != NULL; i++)
+ {
- dllhandle = LoadLibrary (dllname);
+ dllhandle = LoadLibrary (dllnames[i]);
- dllhandle = dlopen (dllname, RTLD_LAZY);
+ dllhandle = dlopen (dllnames[i], RTLD_LAZY);
+ if (dllhandle)
+ break;
+
+ Con_Printf ("Can't load \"%s\".\n", dllnames[i]);
+ }
+
+ // No DLL found
- {
- Con_Printf ("Can't load \"%s\".\n", dllname);
+
+ Con_Printf("\"%s\" loaded.\n", dllnames[i]);
// Get the function adresses
for (func = fcts; func && func->name != NULL; func++)
// Get the function adresses
for (func = fcts; func && func->name != NULL; func++)
- Con_Printf("\"%s\" loaded.\n", dllname);