summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2001-02-23 00:24:43 (GMT)
committerBill Hoffman <bill.hoffman@kitware.com>2001-02-23 00:24:43 (GMT)
commit0b0d1b1d436c6e59ed9ea5c25e1f454fc0ae7827 (patch)
treeed4c5e1e8bc331799cba8c2a797de8228f9f1f97 /Source/cmSystemTools.cxx
parent5d903c6b0f5622a149e0aeda1053ce82b39d2807 (diff)
downloadCMake-0b0d1b1d436c6e59ed9ea5c25e1f454fc0ae7827.zip
CMake-0b0d1b1d436c6e59ed9ea5c25e1f454fc0ae7827.tar.gz
CMake-0b0d1b1d436c6e59ed9ea5c25e1f454fc0ae7827.tar.bz2
ENH: add CMakeCache.txt support
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx102
1 files changed, 102 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index ce2ebc8..141b4ea 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -15,12 +15,14 @@
=========================================================================*/
#include "cmSystemTools.h"
#include "errno.h"
+#include "stdio.h"
#include <sys/stat.h>
#include "cmRegularExpression.h"
#if defined(_MSC_VER) || defined(__BORLANDC__)
#include <windows.h>
#include <direct.h>
+#define _unlink unlink
inline int Mkdir(const char* dir)
{
return _mkdir(dir);
@@ -35,6 +37,8 @@ inline int Mkdir(const char* dir)
}
#endif
+bool cmSystemTools::s_ErrorOccured = false;
+
// adds the elements of the env variable path to the arg passed in
void cmSystemTools::GetPath(std::vector<std::string>& path)
{
@@ -327,6 +331,7 @@ void cmSystemTools::Error(const char* m1, const char* m2)
{
message += m2;
}
+ cmSystemTools::s_ErrorOccured = true;
#if defined(_WIN32) && !defined(__CYGWIN__)
::MessageBox(0, message.c_str(), 0, MB_OK);
std::cerr << message.c_str() << std::endl;
@@ -335,3 +340,100 @@ void cmSystemTools::Error(const char* m1, const char* m2)
#endif
}
+
+
+void cmSystemTools::CopyFileIfDifferent(const char* source,
+ const char* destination)
+{
+ if(cmSystemTools::FilesDiffer(source, destination))
+ {
+ cmSystemTools::Error("doing copy ", destination);
+ cmSystemTools::cmCopyFile(source, destination);
+ }
+}
+
+
+bool cmSystemTools::FilesDiffer(const char* source,
+ const char* destination)
+{
+ struct stat statSource;
+ if (stat(source, &statSource) != 0)
+ {
+ return true;
+ }
+ struct stat statDestination;
+ if (stat(destination, &statDestination) != 0)
+ {
+ return true;
+ }
+ if(statSource.st_size != statDestination.st_size)
+ {
+ return true;
+ }
+ std::ifstream finSource(source);
+ std::ifstream finDestination(destination);
+ if(!finSource || !finDestination)
+ {
+ return true;
+ }
+
+ while(finSource && finDestination)
+ {
+ char s, d;
+ finSource >> s;
+ finDestination >> d;
+ if(s != d)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+void cmSystemTools::cmCopyFile(const char* source,
+ const char* destination)
+{
+ std::ifstream fin(source);
+ char buff[4096];
+ std::ofstream fout(destination);
+ if(!fout )
+ {
+ cmSystemTools::Error("CopyFile failed to open input file", source);
+ }
+ if(!fin)
+ {
+ cmSystemTools::Error("CopyFile failed to open output file", destination);
+ }
+ while(fin)
+ {
+ fin.getline(buff, 4096);
+ if(fin)
+ {
+ fout << buff << "\n";
+ }
+ }
+}
+
+// return true if the file exists
+long int cmSystemTools::ModifiedTime(const char* filename)
+{
+ struct stat fs;
+ if (stat(filename, &fs) != 0)
+ {
+ return 0;
+ }
+ else
+ {
+ return (long int)fs.st_mtime;
+ }
+}
+
+
+
+void cmSystemTools::RemoveFile(const char* source)
+{
+ unlink(source);
+}
+