28 #include "../../idlib/precompiled.h"
29 #include "../posix/posix_public.h"
30 #include "../sys_local.h"
37 #include <sys/types.h>
44 static idStr basepath;
45 static idStr savepath;
67 int ticked, to_ticked;
73 next = ( now & 0xFFFFFFF0 ) + 0x10;
74 want_sleep = ( next-now-1 ) * 1000;
75 if ( want_sleep > 0 ) {
87 static int counter = 0;
89 stats[counter] = to_ticked - ticked;
104 while ( ticked < to_ticked ) {
110 pthread_testcancel();
120 #if defined( ID_DEMO_BUILD )
121 sprintf( savepath,
"%s/.doom3-demo", getenv(
"HOME" ) );
123 sprintf( savepath,
"%s/.doom3", getenv(
"HOME" ) );
125 return savepath.
c_str();
133 static char buf[ 1024 ];
138 sprintf( linkpath,
"/proc/%d/exe", getpid() );
139 len = readlink( linkpath.
c_str(), buf,
sizeof( buf ) );
162 if ( basepath.
Length() ) {
164 testbase = basepath; testbase +=
"/"; testbase +=
BASE_GAMEDIR;
165 if ( stat( testbase.c_str(), &
st ) != -1 && S_ISDIR( st.st_mode ) ) {
166 return basepath.
c_str();
173 testbase = basepath; testbase +=
"/"; testbase +=
BASE_GAMEDIR;
174 if ( stat( testbase.c_str(), &
st ) != -1 && S_ISDIR( st.st_mode ) ) {
175 return basepath.
c_str();
180 common->
Printf(
"WARNING: using hardcoded default base path\n" );
190 return shifted ?
'~' :
'`';
236 assert( signum == SIGFPE );
246 #if defined( __i386__ )
247 unsigned long lo, hi;
249 __asm__ __volatile__ (
251 "xor %%eax,%%eax\n" \
257 :
"=r" (lo),
"=r" (hi) );
258 return (
double) lo + (double) 0xFFFFFFFF * hi;
260 #error unsupported CPU
284 static bool init =
false;
294 fd = open(
"/proc/cpuinfo",
O_RDONLY );
299 common->
Printf(
"measured CPU frequency: %g MHz\n", ret / 1000000.0 );
302 len = read( fd, buf, 4096 );
305 while ( pos < len ) {
307 pos = strchr( buf + pos,
':' ) - buf + 2;
308 end = strchr( buf + pos,
'\n' ) - buf;
309 if ( pos < len && end < len ) {
311 ret = atof( buf + pos );
316 common->
Printf(
"measured CPU frequency: %g MHz\n", ret / 1000000.0 );
319 common->
Printf(
"/proc/cpuinfo CPU frequency: %g MHz\n", ret );
324 pos = strchr( buf + pos,
'\n' ) - buf + 1;
329 common->
Printf(
"measured CPU frequency: %g MHz\n", ret / 1000000.0 );
340 long count, page_size;
343 count = sysconf( _SC_PHYS_PAGES );
345 common->
Printf(
"GetSystemRam: sysconf _SC_PHYS_PAGES failed\n" );
348 page_size = sysconf( _SC_PAGE_SIZE );
349 if ( page_size == -1 ) {
350 common->
Printf(
"GetSystemRam: sysconf _SC_PAGE_SIZE failed\n" );
353 mb= (
int)( (
double)count * (double)page_size / ( 1024 * 1024 ) );
355 mb = ( mb + 8 ) & ~15;
369 bool use_system =
false;
370 if ( strchr( exeName,
' ' ) ) {
375 if ( stat( exeName, &buf ) == -1 ) {
376 printf(
"stat %s failed: %s\n", exeName, strerror( errno ) );
378 if ( chmod( exeName, buf.st_mode | S_IXUSR ) == -1 ) {
379 printf(
"cmod +x %s failed: %s\n", exeName, strerror( errno ) );
390 printf(
"system %s\n", exeName );
394 printf(
"execl %s\n", exeName );
395 execl( exeName, exeName,
NULL );
396 printf(
"execl failed: %s\n", strerror( errno ) );
403 printf(
"system %s\n", exeName );
407 printf(
"execl %s\n", exeName );
408 execl( exeName, exeName,
NULL );
409 printf(
"execl failed: %s\n", strerror( errno ) );
422 const char *script_path;
424 char cmdline[ 1024 ];
426 static bool quit_spamguard =
false;
428 if ( quit_spamguard ) {
429 common->
DPrintf(
"Sys_OpenURL: already in a doexit sequence, ignoring %s\n", url );
440 if ( !script_file ) {
444 if ( !script_file ) {
445 common->
Printf(
"Can't find URL script 'openurl.sh' in either savepath or basepath\n" );
453 quit_spamguard =
true;
524 const char *mcheckstrings[] = {
532 void abrt_func( mcheck_status status ) {
533 Sys_Printf(
"memory consistency failure: %s\n", mcheckstrings[ status + 1 ] );
545 int main(
int argc,
const char **argv) {
549 Sys_Printf(
"memory consistency checking enabled\n" );
static int snPrintf(char *dest, int size, const char *fmt,...) id_attribute((format(printf
void Sys_AsyncThread(void)
double Sys_ClockTicksPerSecond(void)
assert(prefInfo.fullscreenBtn)
idCVarSystem * cvarSystem
double Sys_GetClockTicks(void)
const char * Sys_DefaultSavePath(void)
void Sys_FPU_EnableExceptions(int exceptions)
void Sys_Printf(const char *msg,...)
int Sys_Milliseconds(void)
idFileSystem * fileSystem
virtual idFile * OpenExplicitFileRead(const char *OSPath)=0
void Sys_DebugPrintf(const char *fmt,...)
void Sys_FPU_SetDAZ(bool enable)
void Sys_Sleep(const int time)
int Cmpn(const char *text, int n) const
void Sys_FPE_handler(int signum, siginfo_t *info, void *context)
virtual void Async(void)=0
void Sys_TriggerEvent(int index)
virtual void Frame(void)=0
int main(int argc, const char **argv)
GLuint GLuint GLsizei count
void Posix_SetExit(int ret)
unsigned char Sys_GetConsoleKey(bool shifted)
double MeasureClockTicks(void)
void Posix_EarlyInit(void)
#define LINUX_DEFAULT_PATH
virtual const char * GetCVarString(const char *name) const =0
int Sys_GetSystemRam(void)
void Posix_Shutdown(void)
virtual void StartProcess(const char *exePath, bool quit)=0
virtual void Printf(const char *fmt,...) id_attribute((format(printf
virtual const char * BuildOSPath(const char *base, const char *game, const char *relativePath)=0
virtual void OpenURL(const char *url, bool quit)
const char * Sys_GetProcessorString(void)
const char * Posix_Cwd(void)
const char * c_str(void) const
void Sys_DoPreferences(void)
void Sys_FPU_SetFTZ(bool enable)
void Sys_DoStartProcess(const char *exeName, bool dofork)
virtual void Quit(void)=0
void Sys_InitScanTable(void)
virtual void CloseFile(idFile *f)=0
virtual void DPrintf(const char *fmt,...) id_attribute((format(printf
int sprintf(idStr &string, const char *fmt,...)
virtual void Init(int argc, const char **argv, const char *cmdline)=0
idStr & StripFilename(void)
const char * Sys_EXEPath(void)
cpuid_t Sys_GetProcessorId(void)
const char * Sys_DefaultBasePath(void)
void Posix_LateInit(void)