1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
/*=========================================================================
Program: GCC-XML
Module: $RCSfile: gxSystemTools.cxx,v $
Language: C++
Date: $Date: 2009-02-05 14:10:57 $
Version: $Revision: 1.18 $
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "gxSystemTools.h"
#include <vector>
#include <ctype.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#if !defined(_WIN32) || defined(__CYGWIN__)
#include <limits.h>
#include <stdlib.h>
#include <sys/param.h>
#include <sys/wait.h>
#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <windows.h>
#include <direct.h>
#else
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#endif
//----------------------------------------------------------------------------
bool gxSystemTools::RunCommand(const char* command, std::string& output,
int &retVal)
{
const int BUFFER_SIZE = 4096;
char buffer[BUFFER_SIZE];
#if defined(WIN32) && !defined(__CYGWIN__)
std::string commandToFile = command;
commandToFile += " > ";
std::string tempFile;
char* temp = _tempnam(0, "gccxml");
if(!temp)
{
temp = "gccxmltemp";
}
tempFile += temp;
commandToFile += tempFile;
commandToFile += " 2>&1";
retVal = system(commandToFile.c_str());
std::ifstream fin(tempFile.c_str());
if(!fin)
{
fin.close();
gxSystemTools::RemoveFile(tempFile.c_str());
return false;
}
while(fin)
{
fin.getline(buffer, BUFFER_SIZE);
output += buffer;
output += "\n";
}
fin.close();
gxSystemTools::RemoveFile(tempFile.c_str());
return (retVal == 0);
#else
fflush(stdout);
fflush(stderr);
FILE* cpipe = popen(command, "r");
if(!cpipe)
{
return false;
}
fgets(buffer, BUFFER_SIZE, cpipe);
while(!feof(cpipe))
{
output += buffer;
fgets(buffer, BUFFER_SIZE, cpipe);
}
retVal = pclose(cpipe);
retVal = WEXITSTATUS(retVal);
return (retVal == 0);
#endif
}
//----------------------------------------------------------------------------
bool gxSystemTools::FileCopy(const char* source, const char* destination)
{
return gxsys::SystemTools::CopyFileAlways(source, destination);
}
//----------------------------------------------------------------------------
std::string gxSystemTools::CollapseDirectory(const char* in_dir)
{
return gxsys::SystemTools::CollapseFullPath(in_dir);
}
//----------------------------------------------------------------------------
bool gxSystemTools::ReadRegistryValue(const char *key, std::string &value)
{
return SystemTools::ReadRegistryValue(key, value,
SystemTools::KeyWOW64_32);
}
|