]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/common/cmdlib.c
quake3: delete dead strupr
[xonotic/netradiant.git] / tools / quake3 / common / cmdlib.c
index 103047c029eb85e2542c86d7d199bbdff6fc14ab..60edebad465e5ca22c5d1b156a96b2e932fee5f2 100644 (file)
@@ -1,5 +1,5 @@
 /*
-   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;
 
@@ -72,7 +68,28 @@ void *safe_malloc_info( size_t size, char* info ){
 
        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;
@@ -95,7 +112,8 @@ 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;
@@ -134,10 +152,10 @@ 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
 
 /*
 
@@ -292,16 +310,16 @@ double I_FloatTime( void ){
 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] == '\\' ) {
@@ -318,7 +336,7 @@ void Q_mkdir( const char *path ){
        int retry = 2;
        while ( retry-- )
        {
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
                const char *q = NULL;
                if ( _mkdir( path ) != -1 ) {
                        return;
@@ -330,14 +348,14 @@ void Q_mkdir( const char *path ){
                                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 ) ) {
@@ -481,23 +499,6 @@ int Q_stricmp( const char *s1, const char *s2 ){
        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;
@@ -657,8 +658,7 @@ int    LoadFileBlock( const char *filename, void **bufferptr ){
        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 );
 
@@ -882,11 +882,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;
@@ -934,9 +930,7 @@ float   BigFloat( float l ){
        return l;
 }
 
-
-#else
-
+#else // !GDEF_ARCH_ENDIAN_BIG
 
 short   BigShort( short l ){
        byte b1,b2;
@@ -983,8 +977,7 @@ float   LittleFloat( float l ){
        return l;
 }
 
-
-#endif
+#endif // !GDEF_ARCH_ENDIAN_BIG
 
 
 //=======================================================
@@ -1058,14 +1051,14 @@ void    CreatePath( const char *path ){
        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;
@@ -1081,11 +1074,11 @@ void    CreatePath( const char *path ){
                }
        }
 
-#ifdef _WIN32
+#if GDEF_OS_WINDOWS
        if ( olddrive != -1 ) {
                _chdrive( olddrive );
        }
-#endif
+#endif // !>GDEF_OS_WINDOWS
 }
 
 
@@ -1107,10 +1100,9 @@ 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__ )
+#else // !GDEF_OS_WINDOWS
        usleep( n * 1000 );
-#endif
+#endif // !GDEF_OS_WINDOWS
 }