2 # ifndef DONT_USE_SETDLLDIRECTORY
3 # define _WIN32_WINNT 0x0502
11 # include <mmsystem.h> // timeGetTime
12 # include <time.h> // localtime
13 # include <conio.h> // _kbhit, _getch, _putch
14 # include <io.h> // write; Include this BEFORE darkplaces.h because it uses strncpy which trips DP_STATIC_ASSERT
16 #pragma comment(lib, "winmm.lib")
20 # include <sys/sysctl.h>
23 # include <android/log.h>
27 # include <sys/time.h>
37 #include "taskqueue.h"
43 static char sys_timestring[128];
44 char *Sys_TimeString(const char *timeformat)
46 time_t mytime = time(NULL);
49 localtime_s(&mytm, &mytime);
50 strftime(sys_timestring, sizeof(sys_timestring), timeformat, &mytm);
52 strftime(sys_timestring, sizeof(sys_timestring), timeformat, localtime(&mytime));
54 return sys_timestring;
58 void Sys_Quit (int returnvalue)
60 // Unlock mutexes because the quit command may jump directly here, causing a deadlock
61 if ((cmd_local)->cbuf->lock)
62 Cbuf_Unlock((cmd_local)->cbuf);
63 SV_UnlockThreadMutex();
64 TaskQueue_Frame(true);
66 if (Sys_CheckParm("-profilegameonly"))
67 Sys_AllowProfiling(false);
68 host.state = host_shutdown;
72 Sys_AllowProfiling(false);
75 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
85 void Sys_AllowProfiling(qbool enable)
89 extern void monstartup(const char *libname);
90 extern void moncleanup(void);
92 monstartup("libmain.so");
96 #elif (defined(__linux__) && (defined(__GLIBC__) || defined(__GNU_LIBRARY__))) || defined(__FreeBSD__)
97 extern int moncontrol(int);
104 ===============================================================================
108 ===============================================================================
111 static qbool Sys_LoadDependencyFunctions(dllhandle_t dllhandle, const dllfunction_t *fcts, qbool complain, qbool has_next)
113 const dllfunction_t *func;
116 for (func = fcts; func && func->name != NULL; func++)
117 if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
121 Con_DPrintf (" - missing function \"%s\" - broken library!", func->name);
123 Con_DPrintf("\nContinuing with");
130 for (func = fcts; func && func->name != NULL; func++)
131 *func->funcvariable = NULL;
136 qbool Sys_LoadSelf(dllhandle_t *handle)
138 dllhandle_t dllhandle = 0;
143 dllhandle = LoadLibrary (NULL);
145 dllhandle = dlopen (NULL, RTLD_NOW | RTLD_GLOBAL);
151 qbool Sys_LoadDependency (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts)
154 const dllfunction_t *func;
155 dllhandle_t dllhandle = 0;
162 #ifdef PREFER_PRELOAD
163 dllhandle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
164 if(Sys_LoadDependencyFunctions(dllhandle, fcts, false, false))
166 Con_DPrintf ("All of %s's functions were already linked in! Not loading dynamically...\n", dllnames[0]);
171 Sys_FreeLibrary(&dllhandle);
177 for (func = fcts; func && func->name != NULL; func++)
178 *func->funcvariable = NULL;
180 // Try every possible name
181 Con_DPrintf ("Trying to load library...");
182 for (i = 0; dllnames[i] != NULL; i++)
184 Con_DPrintf (" \"%s\"", dllnames[i]);
186 # ifndef DONT_USE_SETDLLDIRECTORY
188 SetDllDirectory("bin64");
190 SetDllDirectory("bin32");
194 if(Sys_LoadLibrary(dllnames[i], &dllhandle))
196 if (Sys_LoadDependencyFunctions(dllhandle, fcts, true, (dllnames[i+1] != NULL) || (strrchr(sys.argv[0], '/'))))
199 Sys_FreeLibrary (&dllhandle);
203 // see if the names can be loaded relative to the executable path
204 // (this is for Mac OSX which does not check next to the executable)
205 if (!dllhandle && strrchr(sys.argv[0], '/'))
207 char path[MAX_OSPATH];
208 strlcpy(path, sys.argv[0], sizeof(path));
209 strrchr(path, '/')[1] = 0;
210 for (i = 0; dllnames[i] != NULL; i++)
212 char temp[MAX_OSPATH];
213 strlcpy(temp, path, sizeof(temp));
214 strlcat(temp, dllnames[i], sizeof(temp));
215 Con_DPrintf (" \"%s\"", temp);
217 if(Sys_LoadLibrary(temp, &dllhandle))
219 if (Sys_LoadDependencyFunctions(dllhandle, fcts, true, (dllnames[i+1] != NULL) || (strrchr(sys.argv[0], '/'))))
222 Sys_FreeLibrary (&dllhandle);
230 Con_DPrintf(" - failed.\n");
234 Con_DPrintf(" - loaded.\n");
235 Con_Printf("Loaded library \"%s\"\n", dllnames[i]);
244 qbool Sys_LoadLibrary(const char *name, dllhandle_t *handle)
246 dllhandle_t dllhandle = 0;
253 dllhandle = LoadLibrary (name);
255 dllhandle = dlopen (name, RTLD_LAZY | RTLD_GLOBAL);
265 void Sys_FreeLibrary (dllhandle_t* handle)
268 if (handle == NULL || *handle == NULL)
272 FreeLibrary (*handle);
281 void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
285 return (void *)GetProcAddress (handle, name);
287 return (void *)dlsym (handle, name);
295 # define HAVE_TIMEGETTIME 1
296 # define HAVE_QUERYPERFORMANCECOUNTER 1
297 # define HAVE_Sleep 1
301 #if defined(CLOCK_MONOTONIC) || defined(CLOCK_HIRES)
302 # define HAVE_CLOCKGETTIME 1
304 // FIXME improve this check, manpage hints to DST_NONE
305 # define HAVE_GETTIMEOFDAY 1
309 # define HAVE_SELECT 1
313 // FIXME improve this check
314 # define HAVE_USLEEP 1
317 // these are referenced elsewhere
318 cvar_t sys_usenoclockbutbenchmark = {CF_SHARED, "sys_usenoclockbutbenchmark", "0", "don't use ANY real timing, and simulate a clock (for benchmarking); the game then runs as fast as possible. Run a QC mod with bots that does some stuff, then does a quit at the end, to benchmark a server. NEVER do this on a public server."};
319 cvar_t sys_libdir = {CF_READONLY | CF_SHARED, "sys_libdir", "", "Default engine library directory"};
322 static cvar_t sys_debugsleep = {CF_SHARED, "sys_debugsleep", "0", "write requested and attained sleep times to standard output, to be used with gnuplot"};
323 static cvar_t sys_usesdlgetticks = {CF_SHARED, "sys_usesdlgetticks", "0", "use SDL_GetTicks() timer (less accurate, for debugging)"};
324 static cvar_t sys_usesdldelay = {CF_SHARED, "sys_usesdldelay", "0", "use SDL_Delay() (less accurate, for debugging)"};
325 #if HAVE_QUERYPERFORMANCECOUNTER
326 static cvar_t sys_usequeryperformancecounter = {CF_SHARED | CF_ARCHIVE, "sys_usequeryperformancecounter", "0", "use windows QueryPerformanceCounter timer (which has issues on multicore/multiprocessor machines and processors which are designed to conserve power) for timing rather than timeGetTime function (which has issues on some motherboards)"};
328 #if HAVE_CLOCKGETTIME
329 static cvar_t sys_useclockgettime = {CF_SHARED | CF_ARCHIVE, "sys_useclockgettime", "1", "use POSIX clock_gettime function (not adjusted by NTP on some older Linux kernels) for timing rather than gettimeofday (which has issues if the system time is stepped by ntpdate, or apparently on some Xen installations)"};
332 static double benchmark_time; // actually always contains an integer amount of milliseconds, will eventually "overflow"
338 Returns the position (1 to argc-1) in the program's argument list
339 where the given parameter apears, or 0 if not present
342 int Sys_CheckParm (const char *parm)
346 for (i=1 ; i<sys.argc ; i++)
349 continue; // NEXTSTEP sometimes clears appkit vars.
350 if (!strcmp (parm,sys.argv[i]))
357 void Sys_Init_Commands (void)
359 Cvar_RegisterVariable(&sys_debugsleep);
360 Cvar_RegisterVariable(&sys_usenoclockbutbenchmark);
361 Cvar_RegisterVariable(&sys_libdir);
362 #if HAVE_TIMEGETTIME || HAVE_QUERYPERFORMANCECOUNTER || HAVE_CLOCKGETTIME || HAVE_GETTIMEOFDAY
363 if(sys_supportsdlgetticks)
365 Cvar_RegisterVariable(&sys_usesdlgetticks);
366 Cvar_RegisterVariable(&sys_usesdldelay);
369 #if HAVE_QUERYPERFORMANCECOUNTER
370 Cvar_RegisterVariable(&sys_usequeryperformancecounter);
372 #if HAVE_CLOCKGETTIME
373 Cvar_RegisterVariable(&sys_useclockgettime);
377 double Sys_DirtyTime(void)
379 // first all the OPTIONAL timers
381 // benchmark timer (fake clock)
382 if(sys_usenoclockbutbenchmark.integer)
384 double old_benchmark_time = benchmark_time;
386 if(benchmark_time == old_benchmark_time)
387 Sys_Error("sys_usenoclockbutbenchmark cannot run any longer, sorry");
388 return benchmark_time * 0.000001;
390 #if HAVE_QUERYPERFORMANCECOUNTER
391 if (sys_usequeryperformancecounter.integer)
393 // LadyHavoc: note to people modifying this code, DWORD is specifically defined as an unsigned 32bit number, therefore the 65536.0 * 65536.0 is fine.
394 // QueryPerformanceCounter
396 // Windows 95/98/ME/NT/2000/XP
398 // very accurate (CPU cycles)
400 // does not necessarily match realtime too well (tends to get faster and faster in win98)
401 // wraps around occasionally on some platforms (depends on CPU speed and probably other unknown factors)
403 LARGE_INTEGER PerformanceFreq;
404 LARGE_INTEGER PerformanceCount;
406 if (QueryPerformanceFrequency (&PerformanceFreq))
408 QueryPerformanceCounter (&PerformanceCount);
410 timescale = 1.0 / ((double) PerformanceFreq.LowPart + (double) PerformanceFreq.HighPart * 65536.0 * 65536.0);
411 return ((double) PerformanceCount.LowPart + (double) PerformanceCount.HighPart * 65536.0 * 65536.0) * timescale;
415 Con_Printf("No hardware timer available\n");
416 // fall back to other clock sources
417 Cvar_SetValueQuick(&sys_usequeryperformancecounter, false);
422 #if HAVE_CLOCKGETTIME
423 if (sys_useclockgettime.integer)
426 # ifdef CLOCK_MONOTONIC
428 clock_gettime(CLOCK_MONOTONIC, &ts);
431 clock_gettime(CLOCK_HIGHRES, &ts);
433 return (double) ts.tv_sec + ts.tv_nsec / 1000000000.0;
437 // now all the FALLBACK timers
438 if(sys_supportsdlgetticks && sys_usesdlgetticks.integer)
439 return (double) Sys_SDL_GetTicks() / 1000.0;
440 #if HAVE_GETTIMEOFDAY
443 gettimeofday(&tp, NULL);
444 return (double) tp.tv_sec + tp.tv_usec / 1000000.0;
446 #elif HAVE_TIMEGETTIME
448 static int firsttimegettime = true;
451 // Windows 95/98/ME/NT/2000/XP
453 // reasonable accuracy (millisecond)
455 // wraps around every 47 days or so (but this is non-fatal to us, odd times are rejected, only causes a one frame stutter)
457 // make sure the timer is high precision, otherwise different versions of windows have varying accuracy
458 if (firsttimegettime)
461 firsttimegettime = false;
464 return (double) timeGetTime() / 1000.0;
467 // fallback for using the SDL timer if no other timer is available
468 // this calls Sys_Error() if not linking against SDL
469 return (double) Sys_SDL_GetTicks() / 1000.0;
473 extern cvar_t host_maxwait;
474 double Sys_Sleep(double time)
477 uint32_t microseconds;
479 // convert to microseconds
482 if(host_maxwait.value <= 0)
483 time = min(time, 1000000.0);
485 time = min(time, host_maxwait.value * 1000.0);
487 if (time < 1 || host.restless)
488 return 0; // not sleeping this frame
490 microseconds = time; // post-validation to prevent overflow
492 if(sys_usenoclockbutbenchmark.integer)
494 double old_benchmark_time = benchmark_time;
495 benchmark_time += microseconds;
496 if(benchmark_time == old_benchmark_time)
497 Sys_Error("sys_usenoclockbutbenchmark cannot run any longer, sorry");
501 if(sys_debugsleep.integer)
502 Con_Printf("sys_debugsleep: requesting %u ", microseconds);
503 dt = Sys_DirtyTime();
505 // less important on newer libcurl so no need to disturb dedicated servers
506 if (cls.state != ca_dedicated && Curl_Select(microseconds))
508 // a transfer is ready or we finished sleeping
510 else if(sys_supportsdlgetticks && sys_usesdldelay.integer)
511 Sys_SDL_Delay(microseconds / 1000);
521 if (cls.state == ca_dedicated && sv_checkforpacketsduringsleep.integer)
523 List_For_Each_Entry(s, &lhnet_socketlist.list, lhnetsocket_t, list)
525 if (s->address.addresstype == LHNETADDRESSTYPE_INET4 || s->address.addresstype == LHNETADDRESSTYPE_INET6)
527 if (lastfd < s->inetsocket)
528 lastfd = s->inetsocket;
529 #if defined(WIN32) && !defined(_MSC_VER)
530 FD_SET((int)s->inetsocket, &fdreadset);
532 FD_SET((unsigned int)s->inetsocket, &fdreadset);
537 tv.tv_sec = microseconds / 1000000;
538 tv.tv_usec = microseconds % 1000000;
539 // on Win32, select() cannot be used with all three FD list args being NULL according to MSDN
540 // (so much for POSIX...)
541 // bones_was_here: but a zeroed fd_set seems to be tolerated (tested on Win 7)
542 select(lastfd + 1, &fdreadset, NULL, NULL, &tv);
546 usleep(microseconds);
549 Sleep(microseconds / 1000);
552 Sys_SDL_Delay(microseconds / 1000);
555 dt = Sys_DirtyTime() - dt;
556 if(sys_debugsleep.integer)
557 Con_Printf(" got %u oversleep %d\n", (unsigned int)(dt * 1000000), (unsigned int)(dt * 1000000) - microseconds);
558 return (dt < 0 || dt >= 1800) ? 0 : dt;
563 ===============================================================================
567 ===============================================================================
570 void Sys_Print(const char *text)
573 if (developer.integer > 0)
575 __android_log_write(ANDROID_LOG_DEBUG, sys.argv[0], text);
581 // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0).
582 // this is because both go to /dev/tty by default!
584 int origflags = fcntl (sys.outfd, F_GETFL, 0);
585 fcntl (sys.outfd, F_SETFL, origflags & ~O_NONBLOCK);
591 fs_offset_t written = (fs_offset_t)write(sys.outfd, text, (int)strlen(text));
593 break; // sorry, I cannot do anything about this error - without an output
597 fcntl (sys.outfd, F_SETFL, origflags);
600 //fprintf(stdout, "%s", text);
604 /// for the console to report failures inside Con_Printf()
605 void Sys_Printf(const char *fmt, ...)
608 char msg[MAX_INPUTLINE];
610 va_start(argptr,fmt);
611 dpvsnprintf(msg,sizeof(msg),fmt,argptr);
617 /// Reads a line from POSIX stdin or the Windows console
618 char *Sys_ConsoleInput(void)
620 static char text[MAX_INPUTLINE];
622 static unsigned int len = 0;
647 if (len < sizeof (text) - 1)
656 struct timeval timeout = { .tv_sec = 0, .tv_usec = 0 };
659 FD_SET(fileno(stdin), &fdset);
660 if (select(1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(fileno(stdin), &fdset))
661 return fgets(text, sizeof(text), stdin);
668 ===============================================================================
672 ===============================================================================
675 void Sys_Error (const char *error, ...)
678 char string[MAX_INPUTLINE];
680 // change stdin to non blocking
682 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
685 va_start (argptr,error);
686 dpvsnprintf (string, sizeof (string), error, argptr);
689 Con_Printf(CON_ERROR "Engine Error: %s\n", string);
691 // don't want a dead window left blocking the OS UI or the crash dialog
694 Sys_SDL_Dialog("Engine Error", string);
700 static const char *Sys_FindInPATH(const char *name, char namesep, const char *PATH, char pathsep, char *buf, size_t bufsize)
702 const char *p = PATH;
706 while((q = strchr(p, ':')))
708 dpsnprintf(buf, bufsize, "%.*s%c%s", (int)(q-p), p, namesep, name);
709 if(FS_SysFileExists(buf))
713 if(!q) // none found - try the last item
715 dpsnprintf(buf, bufsize, "%s%c%s", p, namesep, name);
716 if(FS_SysFileExists(buf))
724 static const char *Sys_FindExecutableName(void)
729 static char exenamebuf[MAX_OSPATH+1];
731 #if defined(__FreeBSD__)
732 int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
733 size_t exenamebuflen = sizeof(exenamebuf)-1;
734 if (sysctl(mib, 4, exenamebuf, &exenamebuflen, NULL, 0) == 0)
738 #elif defined(__linux__)
739 n = readlink("/proc/self/exe", exenamebuf, sizeof(exenamebuf)-1);
741 if(n > 0 && (size_t)(n) < sizeof(exenamebuf))
746 if(strchr(sys.argv[0], '/'))
747 return sys.argv[0]; // possibly a relative path
749 return Sys_FindInPATH(sys.argv[0], '/', getenv("PATH"), ':', exenamebuf, sizeof(exenamebuf));
753 void Sys_ProvideSelfFD(void)
757 sys.selffd = FS_SysOpenFD(Sys_FindExecutableName(), "rb", false);
760 // for x86 cpus only... (x64 has SSE2_PRESENT)
761 #if defined(SSE_POSSIBLE) && !defined(SSE2_PRESENT)
762 // code from SDL, shortened as we can expect CPUID to work
763 static int CPUID_Features(void)
766 # if (defined(__GNUC__) || defined(__clang__) || defined(__TINYC__)) && defined(__i386__)
768 " movl %%ebx,%%edi\n"
769 " xorl %%eax,%%eax \n"
771 " cpuid # Get family/model/stepping/features\n"
773 " movl %%edi,%%ebx\n"
776 : "%eax", "%ecx", "%edx", "%edi"
778 # elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
782 cpuid ; Get family/model/stepping/features
786 # error SSE_POSSIBLE set but no CPUID implementation
793 qbool Sys_HaveSSE(void)
795 // COMMANDLINEOPTION: SSE: -nosse disables SSE support and detection
796 if(Sys_CheckParm("-nosse"))
801 // COMMANDLINEOPTION: SSE: -forcesse enables SSE support and disables detection
802 if(Sys_CheckParm("-forcesse") || Sys_CheckParm("-forcesse2"))
804 if(CPUID_Features() & (1 << 25))
810 qbool Sys_HaveSSE2(void)
812 // COMMANDLINEOPTION: SSE2: -nosse2 disables SSE2 support and detection
813 if(Sys_CheckParm("-nosse") || Sys_CheckParm("-nosse2"))
818 // COMMANDLINEOPTION: SSE2: -forcesse2 enables SSE2 support and disables detection
819 if(Sys_CheckParm("-forcesse2"))
821 if((CPUID_Features() & (3 << 25)) == (3 << 25)) // SSE is 1<<25, SSE2 is 1<<26
828 /// called to set process priority for dedicated servers
829 #if defined(__linux__)
830 #include <sys/resource.h>
833 void Sys_InitProcessNice (void)
836 sys.nicepossible = false;
837 if(Sys_CheckParm("-nonice"))
840 sys.nicelevel = getpriority(PRIO_PROCESS, 0);
843 Con_Printf("Kernel does not support reading process priority - cannot use niceness\n");
846 if(getrlimit(RLIMIT_NICE, &lim))
848 Con_Printf("Kernel does not support lowering nice level again - cannot use niceness\n");
851 if(lim.rlim_cur != RLIM_INFINITY && sys.nicelevel < (int) (20 - lim.rlim_cur))
853 Con_Printf("Current nice level is below the soft limit - cannot use niceness\n");
856 sys.nicepossible = true;
859 void Sys_MakeProcessNice (void)
861 if(!sys.nicepossible)
865 Con_DPrintf("Process is becoming 'nice'...\n");
866 if(setpriority(PRIO_PROCESS, 0, 19))
867 Con_Printf(CON_ERROR "Failed to raise nice level to %d\n", 19);
870 void Sys_MakeProcessMean (void)
872 if(!sys.nicepossible)
876 Con_DPrintf("Process is becoming 'mean'...\n");
877 if(setpriority(PRIO_PROCESS, 0, sys.nicelevel))
878 Con_Printf(CON_ERROR "Failed to lower nice level to %d\n", sys.nicelevel);
882 void Sys_InitProcessNice (void)
885 void Sys_MakeProcessNice (void)
888 void Sys_MakeProcessMean (void)
893 /** Halt and try not to catch fire.
894 * Writing to any file could corrupt it,
895 * any uneccessary code could crash while we crash.
896 * No malloc() (libgcc should be loaded already) or Con_Printf() allowed here.
898 static void Sys_HandleCrash(int sig)
900 #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1
901 // Before doing anything else grab the stack frame addresses
902 #include <execinfo.h>
903 void *stackframes[32];
904 int framecount = backtrace(stackframes, 32);
907 // Windows doesn't have strsignal()
911 #ifndef WIN32 // or SIGBUS
912 case SIGBUS: sigdesc = "Bus error"; break;
914 case SIGILL: sigdesc = "Illegal instruction"; break;
915 case SIGABRT: sigdesc = "Aborted"; break;
916 case SIGFPE: sigdesc = "Floating point exception"; break;
917 case SIGSEGV: sigdesc = "Segmentation fault"; break;
918 default: sigdesc = "Yo dawg, we hit a bug while hitting a bug";
921 fprintf(stderr, "\n\n\e[1;37;41m Engine Crash: %s (%d) \e[m\n", sigdesc, sig);
922 #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1
923 // the first two addresses will be in this function and in signal() in libc
924 backtrace_symbols_fd(stackframes + 2, framecount - 2, fileno(stderr));
926 fprintf(stderr, "\e[1m%s\e[m\n", engineversion);
928 // DP8 TODO: send a disconnect message indicating we crashed, see CL_DisconnectEx()
930 // don't want a dead window left blocking the OS UI or the crash dialog
934 Sys_SDL_Dialog("Engine Crash", sigdesc);
939 static void Sys_HandleSignal(int sig)
942 // Windows users will likely never see this so no point replicating strsignal()
943 Con_Printf("\nReceived signal %d, exiting...\n", sig);
945 Con_Printf("\nReceived %s signal (%d), exiting...\n", strsignal(sig), sig);
947 host.state = host_shutdown;
950 /// SDL2 only handles SIGINT and SIGTERM by default and doesn't log anything
951 static void Sys_InitSignals(void)
953 // Windows docs say its signal() only accepts these ones
954 signal(SIGABRT, Sys_HandleCrash);
955 signal(SIGFPE, Sys_HandleCrash);
956 signal(SIGILL, Sys_HandleCrash);
957 signal(SIGINT, Sys_HandleSignal);
958 signal(SIGSEGV, Sys_HandleCrash);
959 signal(SIGTERM, Sys_HandleSignal);
961 signal(SIGHUP, Sys_HandleSignal);
962 signal(SIGQUIT, Sys_HandleSignal);
963 signal(SIGBUS, Sys_HandleCrash);
964 signal(SIGPIPE, Sys_HandleSignal);
968 int main (int argc, char **argv)
971 sys.argv = (const char **)argv;
973 // COMMANDLINEOPTION: -noterminal disables console output on stdout
974 if(Sys_CheckParm("-noterminal"))
976 // COMMANDLINEOPTION: -stderr moves console output to stderr
977 else if(Sys_CheckParm("-stderr"))
983 Sys_ProvideSelfFD(); // may call Con_Printf() so must be after sys.outfd is set
986 fcntl(fileno(stdin), F_SETFL, fcntl (fileno(stdin), F_GETFL, 0) | O_NONBLOCK);
990 Sys_AllowProfiling(true);