9 static char sys_timestring[128];
10 char *Sys_TimeString(const char *timeformat)
12 time_t mytime = time(NULL);
13 strftime(sys_timestring, sizeof(sys_timestring), timeformat, localtime(&mytime));
14 return sys_timestring;
18 extern qboolean host_shuttingdown;
19 void Sys_Quit (int returnvalue)
21 if (COM_CheckParm("-profilegameonly"))
22 Sys_AllowProfiling(false);
23 host_shuttingdown = true;
28 void Sys_AllowProfiling(qboolean enable)
30 #if defined(__linux__) || defined(__FreeBSD__)
38 ===============================================================================
42 ===============================================================================
45 qboolean Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts)
47 const dllfunction_t *func;
48 dllhandle_t dllhandle = 0;
56 dllhandle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
59 for (func = fcts; func && func->name != NULL; func++)
60 if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
65 Con_Printf ("All of %s's functions were already linked in! Not loading dynamically...\n", dllnames[0]);
74 for (func = fcts; func && func->name != NULL; func++)
75 *func->funcvariable = NULL;
77 // Try every possible name
78 Con_Printf ("Trying to load library...");
79 for (i = 0; dllnames[i] != NULL; i++)
81 Con_Printf (" \"%s\"", dllnames[i]);
83 dllhandle = LoadLibrary (dllnames[i]);
85 dllhandle = dlopen (dllnames[i], RTLD_LAZY | RTLD_GLOBAL);
91 // see if the names can be loaded relative to the executable path
92 // (this is for Mac OSX which does not check next to the executable)
93 if (!dllhandle && strrchr(com_argv[0], '/'))
95 char path[MAX_OSPATH];
96 strlcpy(path, com_argv[0], sizeof(path));
97 strrchr(path, '/')[1] = 0;
98 for (i = 0; dllnames[i] != NULL; i++)
100 char temp[MAX_OSPATH];
101 strlcpy(temp, path, sizeof(temp));
102 strlcat(temp, dllnames[i], sizeof(temp));
103 Con_Printf (" \"%s\"", temp);
105 dllhandle = LoadLibrary (temp);
107 dllhandle = dlopen (temp, RTLD_LAZY | RTLD_GLOBAL);
117 Con_Printf(" - failed.\n");
121 Con_Printf(" - loaded.\n");
123 // Get the function adresses
124 for (func = fcts; func && func->name != NULL; func++)
125 if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
127 Con_Printf ("Missing function \"%s\" - broken library!\n", func->name);
128 Sys_UnloadLibrary (&dllhandle);
136 void Sys_UnloadLibrary (dllhandle_t* handle)
138 if (handle == NULL || *handle == NULL)
142 FreeLibrary (*handle);
150 void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
153 return (void *)GetProcAddress (handle, name);
155 return (void *)dlsym (handle, name);