updated macro's for platform specific logic

This commit is contained in:
Mark Vejvoda
2010-06-04 20:26:15 +00:00
parent 3acc421404
commit d80a8850b6
2 changed files with 25 additions and 11 deletions

View File

@@ -584,21 +584,24 @@ void createDirectoryPaths(string Path)
{ {
//if (':' != *(path-1)) //if (':' != *(path-1))
{ {
#if defined(_mkdir) || defined(WIN32) #ifdef WIN32
_mkdir(DirName); _mkdir(DirName);
#elif defined(mkdir) #elif defined(__GNUC__)
mkdir(DirName, S_IRWXO); mkdir(DirName, S_IRWXO);
#else
#error "Your compiler needs to support mkdir!"
#endif #endif
} }
} }
*dirName++ = *path++; *dirName++ = *path++;
*dirName = '\0'; *dirName = '\0';
} }
#if defined(_mkdir) || defined(WIN32) #ifdef WIN32
_mkdir(DirName); _mkdir(DirName);
#elif defined(mkdir) #elif defined(__GNUC__)
mkdir(DirName, S_IRWXO); mkdir(DirName, S_IRWXO);
#else
#error "Your compiler needs to support mkdir!"
#endif #endif
} }

View File

@@ -1753,19 +1753,27 @@ void BroadCastSocketThread::execute() {
float Socket::getAveragePingMS(std::string host, int pingCount) { float Socket::getAveragePingMS(std::string host, int pingCount) {
double result = -1; double result = -1;
const bool debugPingOutput = false; const bool debugPingOutput = true;
char szCmd[1024]=""; char szCmd[1024]="";
#ifdef WIN32 #ifdef WIN32
sprintf(szCmd,"ping -n %d %s",pingCount,host.c_str()); sprintf(szCmd,"ping -n %d %s",pingCount,host.c_str());
#else if(debugPingOutput) printf("WIN32 is defined\n");
#elif defined(__GNUC__)
sprintf(szCmd,"ping -c %d %s",pingCount,host.c_str()); sprintf(szCmd,"ping -c %d %s",pingCount,host.c_str());
if(debugPingOutput) printf("NON WIN32 is defined\n");
#else
#error "Your compiler needs to support popen!"
#endif #endif
if(szCmd[0] != '\0') { if(szCmd[0] != '\0') {
FILE *ping= NULL; FILE *ping= NULL;
#if defined(_popen) || defined(WIN32) #ifdef WIN32
ping= _popen(szCmd, "r"); ping= _popen(szCmd, "r");
#elif defined(popen) if(debugPingOutput) printf("WIN32 style _popen\n");
#elif defined(__GNUC__)
ping= popen(szCmd, "r"); ping= popen(szCmd, "r");
if(debugPingOutput) printf("POSIX style _popen\n");
#else
#error "Your compiler needs to support popen!"
#endif #endif
if (ping != NULL){ if (ping != NULL){
char buf[4000]=""; char buf[4000]="";
@@ -1774,10 +1782,13 @@ float Socket::getAveragePingMS(std::string host, int pingCount) {
char *data = fgets(&buf[bufferPos], 256, ping); char *data = fgets(&buf[bufferPos], 256, ping);
bufferPos = strlen(buf); bufferPos = strlen(buf);
} }
#if defined(_pclose) || defined(WIN32) #ifdef WIN32
_pclose(ping); _pclose(ping);
#elif defined(pclose) #elif defined(__GNUC__)
pclose(ping); pclose(ping);
#else
#error "Your compiler needs to support popen!"
#endif #endif
if(debugPingOutput) printf("Running cmd [%s] got [%s]\n",szCmd,buf); if(debugPingOutput) printf("Running cmd [%s] got [%s]\n",szCmd,buf);