14 static char sys_timestring[128];
15 char *Sys_TimeString(const char *timeformat)
17 time_t mytime = time(NULL);
20 localtime_s(&mytm, &mytime);
21 strftime(sys_timestring, sizeof(sys_timestring), timeformat, &mytm);
23 strftime(sys_timestring, sizeof(sys_timestring), timeformat, localtime(&mytime));
25 return sys_timestring;
29 extern qboolean host_shuttingdown;
30 void Sys_Quit (int returnvalue)
32 if (COM_CheckParm("-profilegameonly"))
33 Sys_AllowProfiling(false);
34 host_shuttingdown = true;
39 #if defined(__linux__) || defined(__FreeBSD__)
46 void Sys_AllowProfiling(qboolean enable)
48 #if defined(__linux__) || defined(__FreeBSD__)
55 ===============================================================================
59 ===============================================================================
62 qboolean Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts)
65 const dllfunction_t *func;
66 dllhandle_t dllhandle = 0;
74 dllhandle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
77 for (func = fcts; func && func->name != NULL; func++)
78 if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
83 Con_Printf ("All of %s's functions were already linked in! Not loading dynamically...\n", dllnames[0]);
92 for (func = fcts; func && func->name != NULL; func++)
93 *func->funcvariable = NULL;
95 // Try every possible name
96 Con_Printf ("Trying to load library...");
97 for (i = 0; dllnames[i] != NULL; i++)
99 Con_Printf (" \"%s\"", dllnames[i]);
101 dllhandle = LoadLibrary (dllnames[i]);
103 dllhandle = dlopen (dllnames[i], RTLD_LAZY | RTLD_GLOBAL);
109 // see if the names can be loaded relative to the executable path
110 // (this is for Mac OSX which does not check next to the executable)
111 if (!dllhandle && strrchr(com_argv[0], '/'))
113 char path[MAX_OSPATH];
114 strlcpy(path, com_argv[0], sizeof(path));
115 strrchr(path, '/')[1] = 0;
116 for (i = 0; dllnames[i] != NULL; i++)
118 char temp[MAX_OSPATH];
119 strlcpy(temp, path, sizeof(temp));
120 strlcat(temp, dllnames[i], sizeof(temp));
121 Con_Printf (" \"%s\"", temp);
123 dllhandle = LoadLibrary (temp);
125 dllhandle = dlopen (temp, RTLD_LAZY | RTLD_GLOBAL);
135 Con_Printf(" - failed.\n");
139 Con_Printf(" - loaded.\n");
141 // Get the function adresses
142 for (func = fcts; func && func->name != NULL; func++)
143 if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
145 Con_Printf ("Missing function \"%s\" - broken library!\n", func->name);
146 Sys_UnloadLibrary (&dllhandle);
157 void Sys_UnloadLibrary (dllhandle_t* handle)
160 if (handle == NULL || *handle == NULL)
164 FreeLibrary (*handle);
173 void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
177 return (void *)GetProcAddress (handle, name);
179 return (void *)dlsym (handle, name);