#pragma comment(lib, "winmm.lib")
#endif
#else
+# ifdef __FreeBSD__
+# include <sys/sysctl.h>
+# endif
# include <unistd.h>
# include <fcntl.h>
# include <sys/time.h>
}
-extern qboolean host_shuttingdown;
void Sys_Quit (int returnvalue)
{
// Unlock mutexes because the quit command may jump directly here, causing a deadlock
if (COM_CheckParm("-profilegameonly"))
Sys_AllowProfiling(false);
- host_shuttingdown = true;
+ host.state = host_shutdown;
Host_Shutdown();
exit(returnvalue);
}
else
moncleanup();
#endif
-#elif defined(__linux__) || defined(__FreeBSD__)
+#elif (defined(__linux__) && (defined(__GLIBC__) || defined(__GNU_LIBRARY__))) || defined(__FreeBSD__)
extern int moncontrol(int);
moncontrol(enable);
#endif
#else
dllhandle = dlopen (dllnames[i], RTLD_LAZY | RTLD_GLOBAL);
#endif
- if (Sys_LoadLibraryFunctions(dllhandle, fcts, true, (dllnames[i+1] != NULL) || (strrchr(com_argv[0], '/'))))
+ if (Sys_LoadLibraryFunctions(dllhandle, fcts, true, (dllnames[i+1] != NULL) || (strrchr(sys.argv[0], '/'))))
break;
else
Sys_UnloadLibrary (&dllhandle);
// see if the names can be loaded relative to the executable path
// (this is for Mac OSX which does not check next to the executable)
- if (!dllhandle && strrchr(com_argv[0], '/'))
+ if (!dllhandle && strrchr(sys.argv[0], '/'))
{
char path[MAX_OSPATH];
- strlcpy(path, com_argv[0], sizeof(path));
+ strlcpy(path, sys.argv[0], sizeof(path));
strrchr(path, '/')[1] = 0;
for (i = 0; dllnames[i] != NULL; i++)
{
{
QueryPerformanceCounter (&PerformanceCount);
- #ifdef __BORLANDC__
- timescale = 1.0 / ((double) PerformanceFreq.u.LowPart + (double) PerformanceFreq.u.HighPart * 65536.0 * 65536.0);
- return ((double) PerformanceCount.u.LowPart + (double) PerformanceCount.u.HighPart * 65536.0 * 65536.0) * timescale;
- #else
timescale = 1.0 / ((double) PerformanceFreq.LowPart + (double) PerformanceFreq.HighPart * 65536.0 * 65536.0);
return ((double) PerformanceCount.LowPart + (double) PerformanceCount.HighPart * 65536.0 * 65536.0) * timescale;
- #endif
}
else
{
static const char *Sys_FindExecutableName(void)
{
#if defined(WIN32)
- return com_argv[0];
+ return sys.argv[0];
#else
static char exenamebuf[MAX_OSPATH+1];
ssize_t n = -1;
#if defined(__FreeBSD__)
- n = readlink("/proc/curproc/file", exenamebuf, sizeof(exenamebuf)-1);
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
+ size_t exenamebuflen = sizeof(exenamebuf)-1;
+ if (sysctl(mib, 4, exenamebuf, &exenamebuflen, NULL, 0) == 0)
+ {
+ n = exenamebuflen;
+ }
#elif defined(__linux__)
n = readlink("/proc/self/exe", exenamebuf, sizeof(exenamebuf)-1);
#endif
exenamebuf[n] = 0;
return exenamebuf;
}
- if(strchr(com_argv[0], '/'))
- return com_argv[0]; // possibly a relative path
+ if(strchr(sys.argv[0], '/'))
+ return sys.argv[0]; // possibly a relative path
else
- return Sys_FindInPATH(com_argv[0], '/', getenv("PATH"), ':', exenamebuf, sizeof(exenamebuf));
+ return Sys_FindInPATH(sys.argv[0], '/', getenv("PATH"), ':', exenamebuf, sizeof(exenamebuf));
#endif
}
void Sys_ProvideSelfFD(void)
{
- if(com_selffd != -1)
+ if(sys.selffd != -1)
return;
- com_selffd = FS_SysOpenFD(Sys_FindExecutableName(), "rb", false);
+ sys.selffd = FS_SysOpenFD(Sys_FindExecutableName(), "rb", false);
}
// for x86 cpus only... (x64 has SSE2_PRESENT)
static int CPUID_Features(void)
{
int features = 0;
-# if defined(__GNUC__) && defined(__i386__)
+# if defined((__GNUC__) || (__clang__) || (__TINYC__)) && defined(__i386__)
__asm__ (
" movl %%ebx,%%edi\n"
" xorl %%eax,%%eax \n"
#if defined(__linux__)
#include <sys/resource.h>
#include <errno.h>
-static int nicelevel;
-static qboolean nicepossible;
-static qboolean isnice;
+
void Sys_InitProcessNice (void)
{
struct rlimit lim;
- nicepossible = false;
+ sys.nicepossible = false;
if(COM_CheckParm("-nonice"))
return;
errno = 0;
- nicelevel = getpriority(PRIO_PROCESS, 0);
+ sys.nicelevel = getpriority(PRIO_PROCESS, 0);
if(errno)
{
Con_Printf("Kernel does not support reading process priority - cannot use niceness\n");
Con_Printf("Kernel does not support lowering nice level again - cannot use niceness\n");
return;
}
- if(lim.rlim_cur != RLIM_INFINITY && nicelevel < (int) (20 - lim.rlim_cur))
+ if(lim.rlim_cur != RLIM_INFINITY && sys.nicelevel < (int) (20 - lim.rlim_cur))
{
Con_Printf("Current nice level is below the soft limit - cannot use niceness\n");
return;
}
- nicepossible = true;
- isnice = false;
+ sys.nicepossible = true;
+ sys.isnice = false;
}
void Sys_MakeProcessNice (void)
{
- if(!nicepossible)
+ if(!sys.nicepossible)
return;
- if(isnice)
+ if(sys.isnice)
return;
Con_DPrintf("Process is becoming 'nice'...\n");
if(setpriority(PRIO_PROCESS, 0, 19))
- Con_Errorf("Failed to raise nice level to %d\n", 19);
- isnice = true;
+ Con_Printf(CON_ERROR "Failed to raise nice level to %d\n", 19);
+ sys.isnice = true;
}
void Sys_MakeProcessMean (void)
{
- if(!nicepossible)
+ if(!sys.nicepossible)
return;
- if(!isnice)
+ if(!sys.isnice)
return;
Con_DPrintf("Process is becoming 'mean'...\n");
- if(setpriority(PRIO_PROCESS, 0, nicelevel))
- Con_Errorf("Failed to lower nice level to %d\n", nicelevel);
- isnice = false;
+ if(setpriority(PRIO_PROCESS, 0, sys.nicelevel))
+ Con_Printf(CON_ERROR "Failed to lower nice level to %d\n", sys.nicelevel);
+ sys.isnice = false;
}
#else
void Sys_InitProcessNice (void)