9 static char sys_timestring[128];
10 char *Sys_TimeString(const char *timeformat)
12 time_t mytime = time(NULL);
15 localtime_s(&mytm, &mytime);
16 strftime(sys_timestring, sizeof(sys_timestring), timeformat, &mytm);
18 strftime(sys_timestring, sizeof(sys_timestring), timeformat, localtime(&mytime));
20 return sys_timestring;
24 extern qboolean host_shuttingdown;
25 void Sys_Quit (int returnvalue)
27 if (COM_CheckParm("-profilegameonly"))
28 Sys_AllowProfiling(false);
29 host_shuttingdown = true;
34 #if defined(__linux__) || defined(__FreeBSD__)
41 void Sys_AllowProfiling(qboolean enable)
43 #if defined(__linux__) || defined(__FreeBSD__)
50 ===============================================================================
54 ===============================================================================
57 qboolean Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts)
59 const dllfunction_t *func;
60 dllhandle_t dllhandle = 0;
68 dllhandle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
71 for (func = fcts; func && func->name != NULL; func++)
72 if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
77 Con_Printf ("All of %s's functions were already linked in! Not loading dynamically...\n", dllnames[0]);
86 for (func = fcts; func && func->name != NULL; func++)
87 *func->funcvariable = NULL;
89 // Try every possible name
90 Con_Printf ("Trying to load library...");
91 for (i = 0; dllnames[i] != NULL; i++)
93 Con_Printf (" \"%s\"", dllnames[i]);
95 dllhandle = LoadLibrary (dllnames[i]);
97 dllhandle = dlopen (dllnames[i], RTLD_LAZY | RTLD_GLOBAL);
103 // see if the names can be loaded relative to the executable path
104 // (this is for Mac OSX which does not check next to the executable)
105 if (!dllhandle && strrchr(com_argv[0], '/'))
107 char path[MAX_OSPATH];
108 strlcpy(path, com_argv[0], sizeof(path));
109 strrchr(path, '/')[1] = 0;
110 for (i = 0; dllnames[i] != NULL; i++)
112 char temp[MAX_OSPATH];
113 strlcpy(temp, path, sizeof(temp));
114 strlcat(temp, dllnames[i], sizeof(temp));
115 Con_Printf (" \"%s\"", temp);
117 dllhandle = LoadLibrary (temp);
119 dllhandle = dlopen (temp, RTLD_LAZY | RTLD_GLOBAL);
129 Con_Printf(" - failed.\n");
133 Con_Printf(" - loaded.\n");
135 // Get the function adresses
136 for (func = fcts; func && func->name != NULL; func++)
137 if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
139 Con_Printf ("Missing function \"%s\" - broken library!\n", func->name);
140 Sys_UnloadLibrary (&dllhandle);
148 void Sys_UnloadLibrary (dllhandle_t* handle)
150 if (handle == NULL || *handle == NULL)
154 FreeLibrary (*handle);
162 void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
165 return (void *)GetProcAddress (handle, name);
167 return (void *)dlsym (handle, name);