]> 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 b74c7b3362ba47b5bfeaa1edfff692bf8fbf5c63..60edebad465e5ca22c5d1b156a96b2e932fee5f2 100644 (file)
 #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;
 
@@ -73,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;
@@ -96,6 +112,7 @@ char archivedir[1024];
 #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 ){
@@ -135,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
 
 /*
 
@@ -296,13 +313,13 @@ void Q_getwd( char *out ){
 #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] == '\\' ) {
@@ -331,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 ) ) {
@@ -482,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;
@@ -658,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 );
 
@@ -931,9 +930,7 @@ float   BigFloat( float l ){
        return l;
 }
 
-
-#else
-
+#else // !GDEF_ARCH_ENDIAN_BIG
 
 short   BigShort( short l ){
        byte b1,b2;
@@ -980,8 +977,7 @@ float   LittleFloat( float l ){
        return l;
 }
 
-
-#endif
+#endif // !GDEF_ARCH_ENDIAN_BIG
 
 
 //=======================================================
@@ -1062,7 +1058,7 @@ void    CreatePath( const char *path ){
                olddrive = _getdrive();
                _chdrive( toupper( path[0] ) - 'A' + 1 );
        }
-#endif
+#endif // !GDEF_OS_WINDOWS
 
        if ( path[1] == ':' ) {
                path += 2;
@@ -1082,7 +1078,7 @@ void    CreatePath( const char *path ){
        if ( olddrive != -1 ) {
                _chdrive( olddrive );
        }
-#endif
+#endif // !>GDEF_OS_WINDOWS
 }
 
 
@@ -1106,8 +1102,7 @@ void QCopyFile( const char *from, const char *to ){
 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
 }