diff options
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/sys_local.h | 1 | ||||
-rw-r--r-- | src/sys/sys_main.c | 54 | ||||
-rw-r--r-- | src/sys/sys_unix.c | 45 | ||||
-rw-r--r-- | src/sys/sys_win32.c | 52 |
4 files changed, 108 insertions, 44 deletions
diff --git a/src/sys/sys_local.h b/src/sys/sys_local.h index 9f4de9cf..8f99e7c5 100644 --- a/src/sys/sys_local.h +++ b/src/sys/sys_local.h @@ -52,6 +52,7 @@ char *Sys_StripAppBundle( char *pwd ); void Sys_GLimpSafeInit( void ); void Sys_GLimpInit( void ); void Sys_PlatformInit( void ); +void Sys_PlatformExit( void ); void Sys_SigHandler( int signal ); void Sys_ErrorDialog( const char *error ); void Sys_AnsiColorPrint( const char *msg ); diff --git a/src/sys/sys_main.c b/src/sys/sys_main.c index 53fc57fb..46a795eb 100644 --- a/src/sys/sys_main.c +++ b/src/sys/sys_main.c @@ -208,6 +208,8 @@ static void Sys_Exit( int exitCode ) remove( Sys_PIDFileName( ) ); } + Sys_PlatformExit( ); + exit( exitCode ); } @@ -408,34 +410,6 @@ void Sys_UnloadDll( void *dllHandle ) /* ================= -Sys_TryLibraryLoad -================= -*/ -static void* Sys_TryLibraryLoad(const char* base, const char* gamedir, const char* fname, char* fqpath ) -{ - void* libHandle; - char* fn; - - *fqpath = 0; - - fn = FS_BuildOSPath( base, gamedir, fname ); - Com_Printf( "Sys_LoadDll(%s)... \n", fn ); - - libHandle = Sys_LoadLibrary(fn); - - if(!libHandle) { - Com_Printf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, Sys_LibraryError() ); - return NULL; - } - - Com_Printf ( "Sys_LoadDll(%s): succeeded ...\n", fn ); - Q_strncpyz ( fqpath , fn , MAX_QPATH ) ; - - return libHandle; -} - -/* -================= Sys_LoadDll Used to load a development dll instead of a virtual machine @@ -443,33 +417,31 @@ Used to load a development dll instead of a virtual machine #2 look in fs_basepath ================= */ -void *Sys_LoadDll( const char *name, char *fqpath , +void *Sys_LoadDll( const char *name, intptr_t (**entryPoint)(int, ...), intptr_t (*systemcalls)(intptr_t, ...) ) { void *libHandle; void (*dllEntry)( intptr_t (*syscallptr)(intptr_t, ...) ); char fname[MAX_OSPATH]; - char *basepath; - char *homepath; - char *gamedir; + char *netpath; assert( name ); - Q_snprintf (fname, sizeof(fname), "%s" ARCH_STRING DLL_EXT, name); + Com_sprintf(fname, sizeof(fname), "%s" ARCH_STRING DLL_EXT, name); - // TODO: use fs_searchpaths from files.c - basepath = Cvar_VariableString( "fs_basepath" ); - homepath = Cvar_VariableString( "fs_homepath" ); - gamedir = Cvar_VariableString( "fs_game" ); + netpath = FS_FindDll(fname); - libHandle = Sys_TryLibraryLoad(homepath, gamedir, fname, fqpath); + if(!netpath) { + Com_Printf( "Sys_LoadDll(%s) could not find it\n", fname ); + return NULL; + } - if(!libHandle && basepath) - libHandle = Sys_TryLibraryLoad(basepath, gamedir, fname, fqpath); + Com_Printf( "Loading DLL file: %s\n", netpath); + libHandle = Sys_LoadLibrary(netpath); if(!libHandle) { - Com_Printf ( "Sys_LoadDll(%s) failed to load library\n", name ); + Com_Printf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", netpath, Sys_LibraryError() ); return NULL; } diff --git a/src/sys/sys_unix.c b/src/sys/sys_unix.c index 5ab0f8c7..abbe6237 100644 --- a/src/sys/sys_unix.c +++ b/src/sys/sys_unix.c @@ -56,7 +56,7 @@ char *Sys_DefaultHomePath(void) { if( ( p = getenv( "HOME" ) ) != NULL ) { - Q_strncpyz( homePath, p, sizeof( homePath ) ); + Com_sprintf(homePath, sizeof(homePath), "%s%c", p, PATH_SEP); #ifdef MACOS_X Q_strcat( homePath, sizeof( homePath ), "/Library/Application Support/Tremulous" ); @@ -242,6 +242,36 @@ qboolean Sys_Mkdir( const char *path ) /* ================== +Sys_Mkfifo +================== +*/ +FILE *Sys_Mkfifo( const char *ospath ) +{ + FILE *fifo; + int result; + int fn; + struct stat buf; + + // if file already exists AND is a pipefile, remove it + if( !stat( ospath, &buf ) && S_ISFIFO( buf.st_mode ) ) + FS_Remove( ospath ); + + result = mkfifo( ospath, 0600 ); + if( result != 0 ) + return NULL; + + fifo = fopen( ospath, "w+" ); + if( fifo ) + { + fn = fileno( fifo ); + fcntl( fn, F_SETFL, O_NONBLOCK ); + } + + return fifo; +} + +/* +================== Sys_Cwd ================== */ @@ -499,7 +529,7 @@ void Sys_ErrorDialog( const char *error ) unsigned int size; int f = -1; const char *homepath = Cvar_VariableString( "fs_homepath" ); - const char *gamedir = Cvar_VariableString( "fs_gamedir" ); + const char *gamedir = Cvar_VariableString( "fs_game" ); const char *fileName = "crashlog.txt"; char *ospath = FS_BuildOSPath( homepath, gamedir, fileName ); @@ -742,6 +772,17 @@ void Sys_PlatformInit( void ) /* ============== +Sys_PlatformExit + +Unix specific deinitialisation +============== +*/ +void Sys_PlatformExit( void ) +{ +} + +/* +============== Sys_SetEnv set/unset environment variables (empty value removes it) diff --git a/src/sys/sys_win32.c b/src/sys/sys_win32.c index ad6f18eb..8ca1bf62 100644 --- a/src/sys/sys_win32.c +++ b/src/sys/sys_win32.c @@ -43,6 +43,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // Used to determine where to store user-specific files static char homePath[ MAX_OSPATH ] = { 0 }; +#ifndef DEDICATED +static UINT timerResolution = 0; +#endif + #ifdef __WIN64__ void Sys_SnapVector( float *v ) { @@ -313,6 +317,17 @@ qboolean Sys_Mkdir( const char *path ) } /* +================== +Sys_Mkfifo +Noop on windows because named pipes do not function the same way +================== +*/ +FILE *Sys_Mkfifo( const char *ospath ) +{ + return NULL; +} + +/* ============== Sys_Cwd ============== @@ -699,6 +714,8 @@ Windows specific initialisation void Sys_PlatformInit( void ) { #ifndef DEDICATED + TIMECAPS ptc; + const char *SDL_VIDEODRIVER = getenv( "SDL_VIDEODRIVER" ); if( SDL_VIDEODRIVER ) @@ -709,6 +726,36 @@ void Sys_PlatformInit( void ) } else SDL_VIDEODRIVER_externallySet = qfalse; + + if(timeGetDevCaps(&ptc, sizeof(ptc)) == MMSYSERR_NOERROR) + { + timerResolution = ptc.wPeriodMin; + + if(timerResolution > 1) + { + Com_Printf("Warning: Minimum supported timer resolution is %ums " + "on this system, recommended resolution 1ms\n", timerResolution); + } + + timeBeginPeriod(timerResolution); + } + else + timerResolution = 0; +#endif +} + +/* +============== +Sys_PlatformExit + +Windows specific initialisation +============== +*/ +void Sys_PlatformExit( void ) +{ +#ifndef DEDICATED + if(timerResolution) + timeEndPeriod(timerResolution); #endif } @@ -721,7 +768,10 @@ set/unset environment variables (empty value removes it) */ void Sys_SetEnv(const char *name, const char *value) { - _putenv(va("%s=%s", name, value)); + if(value) + _putenv(va("%s=%s", name, value)); + else + _putenv(va("%s=", name)); } /* |