summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2007-07-16 14:54:32 (GMT)
committerAlexander Neundorf <neundorf@kde.org>2007-07-16 14:54:32 (GMT)
commit5bb94ce16635954f460edcacd5422bc8d53fb8c1 (patch)
tree2632f80554b159a3cd195d4afdc2be1bdc856c17 /Source/cmSystemTools.cxx
parent56838c115ed813711f3e5cbd5bef4646677e5467 (diff)
downloadCMake-5bb94ce16635954f460edcacd5422bc8d53fb8c1.zip
CMake-5bb94ce16635954f460edcacd5422bc8d53fb8c1.tar.gz
CMake-5bb94ce16635954f460edcacd5422bc8d53fb8c1.tar.bz2
ENH: apply patch from Mathieu, add argument -E md5sum to compute md5sums of
files, compatible to md5sum output Alex
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx47
1 files changed, 47 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 41444ad..5e1a38b 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -22,6 +22,7 @@
#include <cmsys/RegularExpression.hxx>
#include <cmsys/Directory.hxx>
#include <cmsys/System.h>
+#include <cmsys/MD5.h>
// support for realpath call
#ifndef _WIN32
@@ -1046,6 +1047,52 @@ bool cmSystemTools::CopyFileIfDifferent(const char* source,
return Superclass::CopyFileIfDifferent(source, destination);
}
+bool cmSystemTools::ComputeFileMD5(const char* source, char* md5out)
+{
+ if(!cmSystemTools::FileExists(source))
+ {
+ return false;
+ }
+
+ // Open files
+#if defined(_WIN32) || defined(__CYGWIN__)
+ cmsys_ios::ifstream fin(source, cmsys_ios::ios::binary | cmsys_ios::ios::in);
+#else
+ cmsys_ios::ifstream fin(source);
+#endif
+ if(!fin)
+ {
+ return false;
+ }
+
+ cmsysMD5* md5 = cmsysMD5_New();
+ cmsysMD5_Initialize(md5);
+
+ // Should be efficient enough on most system:
+ const int bufferSize = 4096;
+ char buffer[bufferSize];
+ // This copy loop is very sensitive on certain platforms with
+ // slightly broken stream libraries (like HPUX). Normally, it is
+ // incorrect to not check the error condition on the fin.read()
+ // before using the data, but the fin.gcount() will be zero if an
+ // error occurred. Therefore, the loop should be safe everywhere.
+ while(fin)
+ {
+ fin.read(buffer, bufferSize);
+ if(fin.gcount())
+ {
+ cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(buffer),
+ fin.gcount());
+ }
+ }
+ cmsysMD5_FinalizeHex(md5, md5out);
+ cmsysMD5_Delete(md5);
+
+ fin.close();
+
+ return true;
+}
+
void cmSystemTools::Glob(const char *directory, const char *regexp,
std::vector<std::string>& files)
{