summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemTools.cxx
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2004-10-17 22:50:49 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2004-10-17 22:50:49 (GMT)
commitbc669730611b765ed0bfda105d11996da98d9e30 (patch)
tree59e3f8a9ae8f94639ff90a9154c45c04b6f9fdbe /Source/kwsys/SystemTools.cxx
parent9a92c429f2f3666e360bbefed3cd14c076edea17 (diff)
downloadCMake-bc669730611b765ed0bfda105d11996da98d9e30.zip
CMake-bc669730611b765ed0bfda105d11996da98d9e30.tar.gz
CMake-bc669730611b765ed0bfda105d11996da98d9e30.tar.bz2
ENH: Add method to find file in parent directories if it exists
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r--Source/kwsys/SystemTools.cxx23
1 files changed, 23 insertions, 0 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 4c4a941..d15181b 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -2071,6 +2071,29 @@ bool SystemTools::IsSubDirectory(const char* cSubdir, const char* cDir)
return false;
}
+kwsys_stl::string SystemTools::FileExistsInParentDirectories(const char* fname,
+ const char* directory, const char* toplevel)
+{
+ kwsys_stl::string file = fname;
+ SystemTools::ConvertToUnixSlashes(file);
+ kwsys_stl::string dir = directory;
+ SystemTools::ConvertToUnixSlashes(dir);
+ while ( 1 )
+ {
+ kwsys_stl::string path = dir + "/" + file;
+ if ( SystemTools::FileExists(path.c_str()) )
+ {
+ return path;
+ }
+ if ( dir.size() < strlen(toplevel) )
+ {
+ break;
+ }
+ dir = SystemTools::GetParentDirectory(dir.c_str());
+ }
+ return "";
+}
+
// These must NOT be initialized. Default initialization to zero is
// necessary.
unsigned int SystemToolsManagerCount;