10 static char sys_timestring[128];
11 char *Sys_TimeString(const char *timeformat)
13 time_t mytime = time(NULL);
14 strftime(sys_timestring, sizeof(sys_timestring), timeformat, localtime(&mytime));
15 return sys_timestring;
19 extern qboolean host_shuttingdown;
22 host_shuttingdown = true;
28 ===============================================================================
32 ===============================================================================
35 qboolean Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts)
37 const dllfunction_t *func;
38 dllhandle_t dllhandle = 0;
45 for (func = fcts; func && func->name != NULL; func++)
46 *func->funcvariable = NULL;
48 // Try every possible name
49 Con_Printf ("Trying to load library...");
50 for (i = 0; dllnames[i] != NULL; i++)
52 Con_Printf (" \"%s\"", dllnames[i]);
54 dllhandle = LoadLibrary (dllnames[i]);
56 dllhandle = dlopen (dllnames[i], RTLD_LAZY);
62 // see if the names can be loaded relative to the executable path
63 // (this is for Mac OSX which does not check next to the executable)
64 if (!dllhandle && strrchr(com_argv[0], '/'))
66 char path[MAX_OSPATH];
67 strlcpy(path, com_argv[0], sizeof(path));
68 strrchr(path, '/')[1] = 0;
69 for (i = 0; dllnames[i] != NULL; i++)
71 char temp[MAX_OSPATH];
72 strlcpy(temp, path, sizeof(temp));
73 strlcat(temp, dllnames[i], sizeof(temp));
74 Con_Printf (" \"%s\"", temp);
76 dllhandle = LoadLibrary (temp);
78 dllhandle = dlopen (temp, RTLD_LAZY);
88 Con_Printf(" - failed.\n");
92 Con_Printf(" - loaded.\n");
94 // Get the function adresses
95 for (func = fcts; func && func->name != NULL; func++)
96 if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
98 Con_Printf ("Missing function \"%s\" - broken library!\n", func->name);
99 Sys_UnloadLibrary (&dllhandle);
107 void Sys_UnloadLibrary (dllhandle_t* handle)
109 if (handle == NULL || *handle == NULL)
113 FreeLibrary (*handle);
121 void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
124 return (void *)GetProcAddress (handle, name);
126 return (void *)dlsym (handle, name);