/*
- Copyright (C) 1999-2006 Id Software, Inc. and contributors.
+ Copyright (C) 1999-2007 id Software, Inc. and contributors.
For a list of contributors, see the accompanying CONTRIBUTORS file.
This file is part of GtkRadiant.
// replaced qprintf with Sys_Printf
#include "cmdlib.h"
+#include "globaldefs.h"
#include "mathlib.h"
#include "inout.h"
#include <sys/types.h>
#include <sys/stat.h>
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
#include <direct.h>
#include <windows.h>
-#endif
-
-#if defined ( __linux__ ) || defined ( __APPLE__ )
-#include <unistd.h>
-#endif
-
-#ifdef NeXT
+#elif GDEF_OS_NEXT
#include <libc.h>
-#endif
+#else // OTHER OS
+#include <unistd.h>
+#endif // OTHER OS
-#define BASEDIRNAME "quake" // assumed to have a 2 or 3 following
-#define PATHSEPERATOR '/'
+#define BASEDIRNAME "quake" // assumed to have a 2 or 3 following
+#define PATHSEPERATOR '/'
-#ifdef SAFE_MALLOC
void *safe_malloc( size_t size ){
void *p;
return p;
}
-#endif
+
+void *safe_malloc0( size_t size ){
+ void *p;
+
+ p = calloc( 1, size );
+ if ( !p ) {
+ Error( "safe_malloc0 failed on allocation of %i bytes", size );
+ }
+
+ return p;
+}
+
+void *safe_malloc0_info( size_t size, char* info ){
+ void *p;
+
+ p = calloc( 1, size );
+ if ( !p ) {
+ Error( "%s: safe_malloc0 failed on allocation of %i bytes", info, size );
+ }
+
+ return p;
+}
// set these before calling CheckParm
int myargc;
#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;
*argc = ex_argc;
*argv = ex_argv;
}
-#else
+#else // !GDEF_OS_WINDOWS
void ExpandWildcards( int *argc, char ***argv ){
}
-#endif
+#endif // !GDEF_OS_WINDOWS
/*
char *ExpandPath( const char *path ){
static char full[1024];
- if ( !qdir ) {
- Error( "ExpandPath called without qdir set" );
- }
if ( path[0] == '/' || path[0] == '\\' || path[1] == ':' ) {
strcpy( full, path );
return full;
return full;
}
-char *ExpandGamePath( const char *path ){
- static char full[1024];
- if ( !gamedir[0] ) {
- Error( "ExpandGamePath called without gamedir set" );
- }
- 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 );
void Q_getwd( char *out ){
int i = 0;
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
_getcwd( out, 256 );
strcat( out, "\\" );
-#else
+#else // !GDEF_OS_WINDOWS
// Gef: Changed from getwd() to getcwd() to avoid potential buffer overflow
if ( !getcwd( out, 256 ) ) {
*out = 0;
}
strcat( out, "/" );
-#endif
+#endif // !GDEF_OS_WINDOWS
while ( out[i] != 0 )
{
if ( out[i] == '\\' ) {
int retry = 2;
while ( retry-- )
{
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
const char *q = NULL;
if ( _mkdir( path ) != -1 ) {
return;
p = q;
}
}
-#else
+#else // !GDEF_OS_WINDOWS
if ( mkdir( path, 0777 ) != -1 ) {
return;
}
if ( errno == ENOENT ) {
p = strrchr( path, '/' );
}
-#endif
+#endif // !GDEF_OS_WINDOWS
if ( p ) {
strncpy( parentbuf, path, sizeof( parentbuf ) );
if ( (int) ( p - path ) < (int) sizeof( parentbuf ) ) {
return Q_strncasecmp( s1, s2, 99999 );
}
-// NOTE TTimo when switching to Multithread DLL (Release/Debug) in the config
-// started getting warnings about that function, prolly a duplicate with the runtime function
-// maybe we still need to have it in linux builds
-/*
- char *strupr (char *start)
- {
- char *in;
- in = start;
- while (*in)
- {
- *in = toupper(*in);
- in++;
- }
- return start;
- }
- */
-
char *strlower( char *start ){
char *in;
in = start;
if ( nBlock > 0 ) {
nAllocSize += MEM_BLOCKSIZE - nBlock;
}
- buffer = safe_malloc( nAllocSize + 1 );
- memset( buffer, 0, nAllocSize + 1 );
+ buffer = safe_malloc0( nAllocSize + 1 );
SafeRead( f, buffer, length );
fclose( f );
============================================================================
*/
-#ifdef _SGI_SOURCE
-#define __BIG_ENDIAN__
-#endif
-
-#ifdef __BIG_ENDIAN__
+#if GDEF_ARCH_ENDIAN_BIG
short LittleShort( short l ){
byte b1,b2;
return l;
}
-
-#else
-
+#else // !GDEF_ARCH_ENDIAN_BIG
short BigShort( short l ){
byte b1,b2;
return l;
}
-
-#endif
+#endif // !GDEF_ARCH_ENDIAN_BIG
//=======================================================
char c;
char dir[1024];
-#ifdef _WIN32
+#if GDEF_OS_WINDOWS
int olddrive = -1;
if ( path[1] == ':' ) {
olddrive = _getdrive();
_chdrive( toupper( path[0] ) - 'A' + 1 );
}
-#endif
+#endif // !GDEF_OS_WINDOWS
if ( path[1] == ':' ) {
path += 2;
}
}
-#ifdef _WIN32
+#if GDEF_OS_WINDOWS
if ( olddrive != -1 ) {
_chdrive( olddrive );
}
-#endif
+#endif // !>GDEF_OS_WINDOWS
}
}
void Sys_Sleep( int n ){
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
Sleep( n );
-#endif
-#if defined ( __linux__ ) || defined ( __APPLE__ )
+#else // !GDEF_OS_WINDOWS
usleep( n * 1000 );
-#endif
+#endif // !GDEF_OS_WINDOWS
}