]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/cmdlib/cmdlib.cpp
radiant: replace StringBuffer with std::string
[xonotic/netradiant.git] / libs / cmdlib / cmdlib.cpp
index 2a9ab55a35182430f3a94c202fb2d7d700ceaa7f..25c5d9addeae227c569410633909a04fb700f12f 100644 (file)
@@ -24,6 +24,7 @@
 //
 
 #include "cmdlib.h"
+#include "globaldefs.h"
 
 #include <string.h>
 #include <stdio.h>
 #include "container/array.h"
 
 
-#if defined ( POSIX )
+#if GDEF_OS_POSIX
 
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
-bool Q_Exec( const char *cmd, char *cmdline, const char *, bool, bool waitfor ){
+bool Q_Exec( const char *cmd, const char *cmdline, const char *, bool, bool waitfor ){
        char fullcmd[2048];
        char *pCmd;
        pid_t pid;
-#ifdef _DEBUG
+#if GDEF_DEBUG
        printf( "Q_Exec damnit\n" );
 #endif
        switch ( ( pid = fork() ) )
@@ -71,12 +72,12 @@ bool Q_Exec( const char *cmd, char *cmdline, const char *, bool, bool waitfor ){
                pCmd = fullcmd;
                while ( *pCmd == ' ' )
                        pCmd++;
-#ifdef _DEBUG
+#if GDEF_DEBUG
                printf( "Running system...\n" );
                printf( "Command: %s\n", pCmd );
 #endif
                system( pCmd );
-#ifdef _DEBUG
+#if GDEF_DEBUG
                printf( "system() returned\n" );
 #endif
                _exit( 0 );
@@ -85,12 +86,12 @@ bool Q_Exec( const char *cmd, char *cmdline, const char *, bool, bool waitfor ){
        return true;
 }
 
-#elif defined( WIN32 )
+#elif GDEF_OS_WINDOWS
 
 #include <windows.h>
 
 // NOTE TTimo windows is VERY nitpicky about the syntax in CreateProcess
-bool Q_Exec( const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole, bool waitfor ){
+bool Q_Exec( const char *cmd, const char *cmdline, const char *execdir, bool bCreateConsole, bool waitfor ){
        PROCESS_INFORMATION ProcessInformation;
        STARTUPINFO startupinfo = {0};
        DWORD dwCreationFlags;
@@ -101,14 +102,12 @@ bool Q_Exec( const char *cmd, char *cmdline, const char *execdir, bool bCreateCo
        else{
                dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
        }
-       const char *pCmd;
-       char *pCmdline;
-       pCmd = cmd;
+       const char *pCmd = cmd;
        if ( pCmd ) {
                while ( *pCmd == ' ' )
                        pCmd++;
        }
-       pCmdline = cmdline;
+       char *pCmdline = strdup(cmdline);
        if ( pCmdline ) {
                while ( *pCmdline == ' ' )
                        pCmdline++;
@@ -129,8 +128,10 @@ bool Q_Exec( const char *cmd, char *cmdline, const char *execdir, bool bCreateCo
                if ( waitfor ) {
                        WaitForSingleObject( ProcessInformation.hProcess, INFINITE );
                }
+               free(pCmdline);
                return true;
        }
+       free(pCmdline);
        return false;
 }