1432
char* source_buf = new char[statSource.st_size];
1433
char* dest_buf = new char[statSource.st_size];
1435
finSource.read(source_buf, statSource.st_size);
1436
finDestination.read(dest_buf, statSource.st_size);
1438
if(statSource.st_size != static_cast<long>(finSource.gcount()) ||
1439
statSource.st_size != static_cast<long>(finDestination.gcount()))
1490
// Compare the files a block at a time.
1491
char source_buf[KWSYS_ST_BUFFER];
1492
char dest_buf[KWSYS_ST_BUFFER];
1493
long nleft = statSource.st_size;
1441
// Failed to read files.
1442
delete [] source_buf;
1496
// Read a block from each file.
1497
long nnext = (nleft > KWSYS_ST_BUFFER)? KWSYS_ST_BUFFER : nleft;
1498
finSource.read(source_buf, nnext);
1499
finDestination.read(dest_buf, nnext);
1501
// If either failed to read assume they are different.
1502
if(static_cast<long>(finSource.gcount()) != nnext ||
1503
static_cast<long>(finDestination.gcount()) != nnext)
1508
// If this block differs the file differs.
1509
if(memcmp((const void*)source_buf, (const void*)dest_buf, nnext) != 0)
1514
// Update the byte count remaining.
1446
int ret = memcmp((const void*)source_buf,
1447
(const void*)dest_buf,
1448
statSource.st_size);
1451
delete [] source_buf;
1518
// No differences found.
1922
size_t SystemTools::GetMaximumFilePathLength()
1924
return KWSYS_SYSTEMTOOLS_MAXPATH;
1839
1928
* Find the file the given name. Searches the given path and then
1840
1929
* the system search path. Returns the full path to the file if it is
1841
1930
* found. Otherwise, the empty string is returned.
1843
1932
kwsys_stl::string SystemTools
1844
::FindFile(const char* name,
1845
const kwsys_stl::vector<kwsys_stl::string>& userPaths)
1933
::FindName(const char* name,
1934
const kwsys_stl::vector<kwsys_stl::string>& userPaths,
1935
bool no_system_path)
1847
1937
// Add the system search path to our path first
1848
kwsys_stl::vector<kwsys_stl::string> path;
1849
SystemTools::GetPath(path, "CMAKE_FILE_PATH");
1850
SystemTools::GetPath(path);
1938
kwsys_stl::vector<kwsys_stl::string> path;
1939
if (!no_system_path)
1941
SystemTools::GetPath(path, "CMAKE_FILE_PATH");
1942
SystemTools::GetPath(path);
1851
1944
// now add the additional paths
1852
path.insert(path.end(), userPaths.begin(), userPaths.end());
1945
for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i = userPaths.begin();
1946
i != userPaths.end(); ++i)
1853
1950
// now look for the file
1854
1951
kwsys_stl::string tryPath;
1855
1952
for(kwsys_stl::vector<kwsys_stl::string>::const_iterator p = path.begin();
1968
* Find the file the given name. Searches the given path and then
1969
* the system search path. Returns the full path to the file if it is
1970
* found. Otherwise, the empty string is returned.
1972
kwsys_stl::string SystemTools
1973
::FindFile(const char* name,
1974
const kwsys_stl::vector<kwsys_stl::string>& userPaths,
1975
bool no_system_path)
1977
kwsys_stl::string tryPath = SystemTools::FindName(name, userPaths, no_system_path);
1978
if(tryPath != "" && !SystemTools::FileIsDirectory(tryPath.c_str()))
1980
return SystemTools::CollapseFullPath(tryPath.c_str());
1982
// Couldn't find the file.
1987
* Find the directory the given name. Searches the given path and then
1988
* the system search path. Returns the full path to the directory if it is
1989
* found. Otherwise, the empty string is returned.
1991
kwsys_stl::string SystemTools
1992
::FindDirectory(const char* name,
1993
const kwsys_stl::vector<kwsys_stl::string>& userPaths,
1994
bool no_system_path)
1996
kwsys_stl::string tryPath = SystemTools::FindName(name, userPaths, no_system_path);
1997
if(tryPath != "" && SystemTools::FileIsDirectory(tryPath.c_str()))
1999
return SystemTools::CollapseFullPath(tryPath.c_str());
2001
// Couldn't find the file.
1872
2006
* Find the executable with the given name. Searches the given path and then
1873
2007
* the system search path. Returns the full path to the executable if it is
1874
2008
* found. Otherwise, the empty string is returned.
1876
2010
kwsys_stl::string SystemTools::FindProgram(
1878
2012
const kwsys_stl::vector<kwsys_stl::string>& userPaths,
1879
2013
bool no_system_path)
2015
if(!nameIn || !*nameIn)
1885
// See if the executable exists as written.
1886
if(SystemTools::FileExists(name) &&
1887
!SystemTools::FileIsDirectory(name))
1889
return SystemTools::CollapseFullPath(name);
1891
kwsys_stl::string tryPath = name;
1892
tryPath += SystemTools::GetExecutableExtension();
1893
if(SystemTools::FileExists(tryPath.c_str()) &&
1894
!SystemTools::FileIsDirectory(tryPath.c_str()))
1896
return SystemTools::CollapseFullPath(tryPath.c_str());
2019
kwsys_stl::string name = nameIn;
2020
kwsys_stl::vector<kwsys_stl::string> extensions;
2021
#if defined (_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
2022
bool hasExtension = false;
2023
// check to see if the name already has a .xxx at
2025
if(name.size() > 3 && name[name.size()-4] == '.')
2027
hasExtension = true;
2029
// on windows try .com then .exe
2032
extensions.push_back(".com");
2033
extensions.push_back(".exe");
2036
kwsys_stl::string tryPath;
2038
// first try with extensions if the os supports them
2039
if(extensions.size())
2041
for(kwsys_stl::vector<kwsys_stl::string>::iterator i =
2042
extensions.begin(); i != extensions.end(); ++i)
2046
if(SystemTools::FileExists(tryPath.c_str()) &&
2047
!SystemTools::FileIsDirectory(tryPath.c_str()))
2049
return SystemTools::CollapseFullPath(tryPath.c_str());
2053
// now try just the name
2055
if(SystemTools::FileExists(tryPath.c_str()) &&
2056
!SystemTools::FileIsDirectory(tryPath.c_str()))
2058
return SystemTools::CollapseFullPath(tryPath.c_str());
2060
// now construct the path
1898
2061
kwsys_stl::vector<kwsys_stl::string> path;
1899
SystemTools::GetPath(path, "CMAKE_PROGRAM_PATH");
1900
2062
// Add the system search path to our path.
1901
2063
if (!no_system_path)
1903
2065
SystemTools::GetPath(path);
1906
2067
// now add the additional paths
1907
path.insert(path.end(), userPaths.begin(), userPaths.end());
1909
for(kwsys_stl::vector<kwsys_stl::string>::const_iterator p = path.begin();
2068
for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i =
2069
userPaths.begin(); i != userPaths.end(); ++i)
2074
for(kwsys_stl::vector<kwsys_stl::string>::iterator p = path.begin();
1910
2075
p != path.end(); ++p)
1915
if(SystemTools::FileExists(tryPath.c_str()) &&
1916
!SystemTools::FileIsDirectory(tryPath.c_str()))
1918
return SystemTools::CollapseFullPath(tryPath.c_str());
1922
if(SystemTools::FileExists(tryPath.c_str()) &&
1923
!SystemTools::FileIsDirectory(tryPath.c_str()))
1925
return SystemTools::CollapseFullPath(tryPath.c_str());
2078
// Remove double quotes from the path on windows
2079
SystemTools::ReplaceString(*p, "\"", "");
1931
tryPath += SystemTools::GetExecutableExtension();
1932
if(SystemTools::FileExists(tryPath.c_str()) &&
1933
!SystemTools::FileIsDirectory(tryPath.c_str()))
2081
// first try with extensions
2082
if(extensions.size())
1935
return SystemTools::CollapseFullPath(tryPath.c_str());
2084
for(kwsys_stl::vector<kwsys_stl::string>::iterator ext
2085
= extensions.begin(); ext != extensions.end(); ++ext)
2091
if(SystemTools::FileExists(tryPath.c_str()) &&
2092
!SystemTools::FileIsDirectory(tryPath.c_str()))
2094
return SystemTools::CollapseFullPath(tryPath.c_str());
2098
// now try it without them
2102
if(SystemTools::FileExists(tryPath.c_str()) &&
2103
!SystemTools::FileIsDirectory(tryPath.c_str()))
2105
return SystemTools::CollapseFullPath(tryPath.c_str());
1939
2108
// Couldn't find the program.
2112
kwsys_stl::string SystemTools::FindProgram(
2113
const kwsys_stl::vector<kwsys_stl::string>& names,
2114
const kwsys_stl::vector<kwsys_stl::string>& path,
2117
for(kwsys_stl::vector<kwsys_stl::string>::const_iterator it = names.begin();
2118
it != names.end() ; ++it)
2120
// Try to find the program.
2121
kwsys_stl::string result = SystemTools::FindProgram(it->c_str(),
2124
if ( !result.empty() )
1945
2133
* Find the library with the given name. Searches the given path and then
1957
2145
return SystemTools::CollapseFullPath(name);
1960
2148
// Add the system search path to our path.
1961
2149
kwsys_stl::vector<kwsys_stl::string> path;
1962
2150
SystemTools::GetPath(path);
1963
2151
// now add the additional paths
1964
path.insert(path.end(), userPaths.begin(), userPaths.end());
2152
for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i = userPaths.begin();
2153
i != userPaths.end(); ++i)
1965
2157
kwsys_stl::string tryPath;
1966
2158
for(kwsys_stl::vector<kwsys_stl::string>::const_iterator p = path.begin();
1967
2159
p != path.end(); ++p)
2161
#if defined(__APPLE__)
2165
tryPath += ".framework";
2166
if(SystemTools::FileExists(tryPath.c_str())
2167
&& SystemTools::FileIsDirectory(tryPath.c_str()))
2169
return SystemTools::CollapseFullPath(tryPath.c_str());
1969
2172
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__)
1971
2174
tryPath += "/";
1972
2175
tryPath += name;
1973
2176
tryPath += ".lib";
1974
if(SystemTools::FileExists(tryPath.c_str())
2177
if(SystemTools::FileExists(tryPath.c_str())
1975
2178
&& !SystemTools::FileIsDirectory(tryPath.c_str()))
1977
2180
return SystemTools::CollapseFullPath(tryPath.c_str());
2334
2545
SystemTools::CheckTranslationPath(newPath);
2336
2547
newPath = SystemTools::GetActualCaseForPath(newPath.c_str());
2548
SystemTools::ConvertToUnixSlashes(newPath);
2338
2550
// Return the reconstructed path.
2339
2551
return newPath;
2554
// compute the relative path from here to there
2555
kwsys_stl::string SystemTools::RelativePath(const char* local, const char* remote)
2557
if(!SystemTools::FileIsFullPath(local))
2561
if(!SystemTools::FileIsFullPath(remote))
2566
// split up both paths into arrays of strings using / as a separator
2567
kwsys_stl::vector<kwsys::String> localSplit = SystemTools::SplitString(local, '/', true);
2568
kwsys_stl::vector<kwsys::String> remoteSplit = SystemTools::SplitString(remote, '/', true);
2569
kwsys_stl::vector<kwsys::String> commonPath; // store shared parts of path in this array
2570
kwsys_stl::vector<kwsys::String> finalPath; // store the final relative path here
2571
// count up how many matching directory names there are from the start
2572
unsigned int sameCount = 0;
2574
((sameCount <= (localSplit.size()-1)) && (sameCount <= (remoteSplit.size()-1)))
2576
// for windows and apple do a case insensitive string compare
2577
#if defined(_WIN32) || defined(__APPLE__)
2578
SystemTools::Strucmp(localSplit[sameCount].c_str(),
2579
remoteSplit[sameCount].c_str()) == 0
2581
localSplit[sameCount] == remoteSplit[sameCount]
2585
// put the common parts of the path into the commonPath array
2586
commonPath.push_back(localSplit[sameCount]);
2587
// erase the common parts of the path from the original path arrays
2588
localSplit[sameCount] = "";
2589
remoteSplit[sameCount] = "";
2592
// If there is nothing in common but the root directory, then just
2593
// return the full path.
2599
// for each entry that is not common in the local path
2600
// add a ../ to the finalpath array, this gets us out of the local
2601
// path into the remote dir
2602
for(unsigned int i = 0; i < localSplit.size(); ++i)
2604
if(localSplit[i].size())
2606
finalPath.push_back("../");
2609
// for each entry that is not common in the remote path add it
2610
// to the final path.
2611
for(kwsys_stl::vector<String>::iterator vit = remoteSplit.begin();
2612
vit != remoteSplit.end(); ++vit)
2616
finalPath.push_back(*vit);
2619
kwsys_stl::string relativePath; // result string
2620
// now turn the array of directories into a unix path by puttint /
2621
// between each entry that does not already have one
2622
for(kwsys_stl::vector<String>::iterator vit1 = finalPath.begin();
2623
vit1 != finalPath.end(); ++vit1)
2625
if(relativePath.size() && relativePath[relativePath.size()-1] != '/')
2627
relativePath += "/";
2629
relativePath += *vit1;
2631
return relativePath;
2343
2634
// OK, some fun stuff to get the actual case of a given path.
2344
2635
// Basically, you just need to call ShortPath, then GetLongPathName,