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 void Sys_AllowProfiling(qboolean enable)
36 #if defined(__linux__) || defined(__FreeBSD__)
44 ===============================================================================
48 ===============================================================================
51 qboolean Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts)
53 const dllfunction_t *func;
54 dllhandle_t dllhandle = 0;
62 dllhandle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
65 for (func = fcts; func && func->name != NULL; func++)
66 if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
71 Con_Printf ("All of %s's functions were already linked in! Not loading dynamically...\n", dllnames[0]);
80 for (func = fcts; func && func->name != NULL; func++)
81 *func->funcvariable = NULL;
83 // Try every possible name
84 Con_Printf ("Trying to load library...");
85 for (i = 0; dllnames[i] != NULL; i++)
87 Con_Printf (" \"%s\"", dllnames[i]);
89 dllhandle = LoadLibrary (dllnames[i]);
91 dllhandle = dlopen (dllnames[i], RTLD_LAZY | RTLD_GLOBAL);
97 // see if the names can be loaded relative to the executable path
98 // (this is for Mac OSX which does not check next to the executable)
99 if (!dllhandle && strrchr(com_argv[0], '/'))
101 char path[MAX_OSPATH];
102 strlcpy(path, com_argv[0], sizeof(path));
103 strrchr(path, '/')[1] = 0;
104 for (i = 0; dllnames[i] != NULL; i++)
106 char temp[MAX_OSPATH];
107 strlcpy(temp, path, sizeof(temp));
108 strlcat(temp, dllnames[i], sizeof(temp));
109 Con_Printf (" \"%s\"", temp);
111 dllhandle = LoadLibrary (temp);
113 dllhandle = dlopen (temp, RTLD_LAZY | RTLD_GLOBAL);
123 Con_Printf(" - failed.\n");
127 Con_Printf(" - loaded.\n");
129 // Get the function adresses
130 for (func = fcts; func && func->name != NULL; func++)
131 if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
133 Con_Printf ("Missing function \"%s\" - broken library!\n", func->name);
134 Sys_UnloadLibrary (&dllhandle);
142 void Sys_UnloadLibrary (dllhandle_t* handle)
144 if (handle == NULL || *handle == NULL)
148 FreeLibrary (*handle);
156 void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
159 return (void *)GetProcAddress (handle, name);
161 return (void *)dlsym (handle, name);