X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=sys_shared.c;h=1893c219f460ebbdf49145a8ed8fa530e06575eb;hb=783c61300adf71a38a5c9edb323d6f5ff90ac51d;hp=d1bc7fe60c90029f8bbdcb2e35b4b644fdecdb47;hpb=ff46d6ff516fda192c5adc55a5c9b82007545bd2;p=xonotic%2Fdarkplaces.git diff --git a/sys_shared.c b/sys_shared.c index d1bc7fe6..1893c219 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -1,9 +1,10 @@ #include "quakedef.h" -#include +# include #ifndef WIN32 -#include -#include +# include +# include +# include #endif extern cvar_t timestamps; @@ -48,14 +49,20 @@ static char qfont_table[256] = { 'x', 'y', 'z', '{', '|', '}', '~', '<' }; +static char sys_timestring[128]; +char *Sys_TimeString(const char *timeformat) +{ + time_t mytime = time(NULL); + strftime(sys_timestring, sizeof(sys_timestring), timeformat, localtime(&mytime)); + return sys_timestring; +} + #define MAXPRINTMSG 16384 void Sys_Print(const char *msg) { unsigned char *p; - // Time stamp - char stamp[128]; // String we print char final[MAXPRINTMSG]; @@ -63,13 +70,9 @@ void Sys_Print(const char *msg) return; if (timestamps.integer) - { - time_t mytime = time(NULL); - strftime(stamp, sizeof(stamp), timeformat.string, localtime(&mytime)); - snprintf(final, sizeof(final), "%s%s", stamp, msg); - } + snprintf(final, sizeof(final), "%s%s", Sys_TimeString(timeformat.string), msg); else - strncpy(final, msg, sizeof(final)); + strlcpy (final, msg, sizeof (final)); // LordHavoc: make sure the string is terminated final[MAXPRINTMSG-1] = 0; @@ -90,6 +93,13 @@ void Sys_Printf(const char *fmt, ...) Sys_Print(msg); } +extern qboolean host_shuttingdown; +void Sys_Quit (void) +{ + host_shuttingdown = true; + Host_Shutdown(); + exit(0); +} char engineversion[128]; @@ -106,6 +116,8 @@ void Sys_Shared_EarlyInit(void) os = "Linux"; #elif defined(WIN32) os = "Windows"; +#elif defined(__FreeBSD__) + os = "FreeBSD"; #elif defined(__NetBSD__) os = "NetBSD"; #elif defined(__OpenBSD__) @@ -115,6 +127,7 @@ void Sys_Shared_EarlyInit(void) #endif snprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring); +// COMMANDLINEOPTION: Console: -nostdout disables text output to the terminal the game was launched from if (COM_CheckParm("-nostdout")) sys_nostdout = 1; else @@ -133,26 +146,56 @@ DLL MANAGEMENT =============================================================================== */ -#ifndef WIN32 -#include -#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)