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 host_shuttingdown = true;
27 ===============================================================================
31 ===============================================================================
34 qboolean Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts)
36 const dllfunction_t *func;
37 dllhandle_t dllhandle = 0;
45 dllhandle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
48 for (func = fcts; func && func->name != NULL; func++)
49 if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
54 Con_Printf ("All of %s's functions were already linked in! Not loading dynamically...\n", dllnames[0]);
63 for (func = fcts; func && func->name != NULL; func++)
64 *func->funcvariable = NULL;
66 // Try every possible name
67 Con_Printf ("Trying to load library...");
68 for (i = 0; dllnames[i] != NULL; i++)
70 Con_Printf (" \"%s\"", dllnames[i]);
72 dllhandle = LoadLibrary (dllnames[i]);
74 dllhandle = dlopen (dllnames[i], RTLD_LAZY | RTLD_GLOBAL);
80 // see if the names can be loaded relative to the executable path
81 // (this is for Mac OSX which does not check next to the executable)
82 if (!dllhandle && strrchr(com_argv[0], '/'))
84 char path[MAX_OSPATH];
85 strlcpy(path, com_argv[0], sizeof(path));
86 strrchr(path, '/')[1] = 0;
87 for (i = 0; dllnames[i] != NULL; i++)
89 char temp[MAX_OSPATH];
90 strlcpy(temp, path, sizeof(temp));
91 strlcat(temp, dllnames[i], sizeof(temp));
92 Con_Printf (" \"%s\"", temp);
94 dllhandle = LoadLibrary (temp);
96 dllhandle = dlopen (temp, RTLD_LAZY | RTLD_GLOBAL);
106 Con_Printf(" - failed.\n");
110 Con_Printf(" - loaded.\n");
112 // Get the function adresses
113 for (func = fcts; func && func->name != NULL; func++)
114 if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
116 Con_Printf ("Missing function \"%s\" - broken library!\n", func->name);
117 Sys_UnloadLibrary (&dllhandle);
125 void Sys_UnloadLibrary (dllhandle_t* handle)
127 if (handle == NULL || *handle == NULL)
131 FreeLibrary (*handle);
139 void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
142 return (void *)GetProcAddress (handle, name);
144 return (void *)dlsym (handle, name);