X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=tools%2Fquake3%2Fcommon%2Fcmdlib.c;h=b74c7b3362ba47b5bfeaa1edfff692bf8fbf5c63;hb=e744bb6dadcd57fff460b7e6409ecd61bfe272c7;hp=3c01cc9923663a98c1fa282127d6755f6d7a4573;hpb=943424faa1514f24b63524161d299734a8c3f8bd;p=xonotic%2Fnetradiant.git diff --git a/tools/quake3/common/cmdlib.c b/tools/quake3/common/cmdlib.c index 3c01cc99..b74c7b33 100644 --- a/tools/quake3/common/cmdlib.c +++ b/tools/quake3/common/cmdlib.c @@ -29,17 +29,18 @@ // replaced qprintf with Sys_Printf #include "cmdlib.h" +#include "globaldefs.h" #include "mathlib.h" #include "inout.h" #include #include -#ifdef _WIN32 +#if GDEF_OS_WINDOWS #include #include #endif -#if defined ( __linux__ ) || defined ( __APPLE__ ) +#if GDEF_OS_LINUX || GDEF_OS_MACOS #include #endif @@ -95,7 +96,7 @@ char archivedir[1024]; #define MAX_EX_ARGC 1024 int ex_argc; char *ex_argv[MAX_EX_ARGC]; -#ifdef _WIN32 +#if GDEF_OS_WINDOWS #include "io.h" void ExpandWildcards( int *argc, char ***argv ){ struct _finddata_t fileinfo; @@ -188,7 +189,7 @@ void SetQdirFromPath( const char *path ){ } strncpy( qdir, path, c + len + count - path ); Sys_Printf( "qdir: %s\n", qdir ); - for ( i = 0; i < strlen( qdir ); i++ ) + for ( i = 0; i < (int) strlen( qdir ); i++ ) { if ( qdir[i] == '\\' ) { qdir[i] = '/'; @@ -201,7 +202,7 @@ void SetQdirFromPath( const char *path ){ if ( *c == '/' || *c == '\\' ) { strncpy( gamedir, path, c + 1 - path ); - for ( i = 0; i < strlen( gamedir ); i++ ) + for ( i = 0; i < (int) strlen( gamedir ); i++ ) { if ( gamedir[i] == '\\' ) { gamedir[i] = '/'; @@ -252,30 +253,6 @@ char *ExpandPath( const char *path ){ return full; } -char *ExpandGamePath( const char *path ){ - static char full[1024]; - if ( path[0] == '/' || path[0] == '\\' || path[1] == ':' ) { - strcpy( full, path ); - return full; - } - sprintf( full, "%s%s", gamedir, path ); - return full; -} - -char *ExpandPathAndArchive( const char *path ){ - char *expanded; - char archivename[1024]; - - expanded = ExpandPath( path ); - - if ( archive ) { - sprintf( archivename, "%s/%s", archivedir, path ); - QCopyFile( expanded, archivename ); - } - return expanded; -} - - char *copystring( const char *s ){ char *b; b = safe_malloc( strlen( s ) + 1 ); @@ -316,12 +293,14 @@ double I_FloatTime( void ){ void Q_getwd( char *out ){ int i = 0; -#ifdef WIN32 +#if GDEF_OS_WINDOWS _getcwd( out, 256 ); strcat( out, "\\" ); #else // Gef: Changed from getwd() to getcwd() to avoid potential buffer overflow - getcwd( out, 256 ); + if ( !getcwd( out, 256 ) ) { + *out = 0; + } strcat( out, "/" ); #endif while ( out[i] != 0 ) @@ -335,15 +314,42 @@ void Q_getwd( char *out ){ void Q_mkdir( const char *path ){ -#ifdef WIN32 - if ( _mkdir( path ) != -1 ) { - return; - } + char parentbuf[256]; + const char *p = NULL; + int retry = 2; + while ( retry-- ) + { +#if GDEF_OS_WINDOWS + const char *q = NULL; + if ( _mkdir( path ) != -1 ) { + return; + } + if ( errno == ENOENT ) { + p = strrchr( path, '/' ); + q = strrchr( path, '\\' ); + if ( q && ( !p || q < p ) ) { + p = q; + } + } #else - if ( mkdir( path, 0777 ) != -1 ) { - return; - } + if ( mkdir( path, 0777 ) != -1 ) { + return; + } + if ( errno == ENOENT ) { + p = strrchr( path, '/' ); + } #endif + if ( p ) { + strncpy( parentbuf, path, sizeof( parentbuf ) ); + if ( (int) ( p - path ) < (int) sizeof( parentbuf ) ) { + parentbuf[p - path] = 0; + Sys_Printf( "mkdir: %s: creating parent %s first\n", path, parentbuf ); + Q_mkdir( parentbuf ); + continue; + } + } + break; + } if ( errno != EEXIST ) { Error( "mkdir %s: %s",path, strerror( errno ) ); } @@ -877,11 +883,7 @@ int ParseNum( const char *str ){ ============================================================================ */ -#ifdef _SGI_SOURCE -#define __BIG_ENDIAN__ -#endif - -#ifdef __BIG_ENDIAN__ +#if GDEF_ARCH_ENDIAN_BIG short LittleShort( short l ){ byte b1,b2; @@ -1053,7 +1055,7 @@ void CreatePath( const char *path ){ char c; char dir[1024]; -#ifdef _WIN32 +#if GDEF_OS_WINDOWS int olddrive = -1; if ( path[1] == ':' ) { @@ -1076,7 +1078,7 @@ void CreatePath( const char *path ){ } } -#ifdef _WIN32 +#if GDEF_OS_WINDOWS if ( olddrive != -1 ) { _chdrive( olddrive ); } @@ -1102,10 +1104,10 @@ void QCopyFile( const char *from, const char *to ){ } void Sys_Sleep( int n ){ -#ifdef WIN32 +#if GDEF_OS_WINDOWS Sleep( n ); #endif -#if defined ( __linux__ ) || defined ( __APPLE__ ) +#if GDEF_OS_LINUX || GDEF_OS_MACOS usleep( n * 1000 ); #endif }