#if GDEF_OS_WINDOWS
#include <direct.h>
#include <windows.h>
-#endif
-
-#if GDEF_OS_LINUX || GDEF_OS_MACOS
-#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];
+
#if GDEF_OS_WINDOWS
#include "io.h"
void ExpandWildcards( int *argc, char ***argv ){
*argc = ex_argc;
*argv = ex_argv;
}
-#else
+#else // !GDEF_OS_WINDOWS
void ExpandWildcards( int *argc, char ***argv ){
}
-#endif
+#endif // !GDEF_OS_WINDOWS
/*
#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] == '\\' ) {
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 );
return l;
}
-
-#else
-
+#else // !GDEF_ARCH_ENDIAN_BIG
short BigShort( short l ){
byte b1,b2;
return l;
}
-
-#endif
+#endif // !GDEF_ARCH_ENDIAN_BIG
//=======================================================
olddrive = _getdrive();
_chdrive( toupper( path[0] ) - 'A' + 1 );
}
-#endif
+#endif // !GDEF_OS_WINDOWS
if ( path[1] == ':' ) {
path += 2;
if ( olddrive != -1 ) {
_chdrive( olddrive );
}
-#endif
+#endif // !>GDEF_OS_WINDOWS
}
void Sys_Sleep( int n ){
#if GDEF_OS_WINDOWS
Sleep( n );
-#endif
-#if GDEF_OS_LINUX || GDEF_OS_MACOS
+#else // !GDEF_OS_WINDOWS
usleep( n * 1000 );
-#endif
+#endif // !GDEF_OS_WINDOWS
}