diff --git a/SystemTools.cxx b/SystemTools.cxx
index 937c4ee7ddee0b31b86e24720b3045f1ba882aeb..591e49605a56ad19edd9977405b588388883803f 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -2010,6 +2010,46 @@ bool SystemTools::SetPermissions(const char* file, mode_t mode)
   return true;
 }
 
+std::string SystemTools::GetParentDirectory(const char* fileOrDir)
+{
+  if ( !fileOrDir || !*fileOrDir )
+    {
+    return "";
+    }
+  std::string res = fileOrDir;
+  SystemTools::ConvertToUnixSlashes(res);
+  std::string::size_type cc = res.size()-1;
+  if ( res[cc] == '/' )
+    {
+    cc --;
+    }
+  for ( ; cc > 0; cc -- )
+    {
+    if ( res[cc] == '/' )
+      {
+      break;
+      }
+    }
+  return res.substr(0, cc);
+}
+
+bool SystemTools::IsSubDirectory(const char* cSubdir, const char* cDir)
+{
+  std::string subdir = cSubdir;
+  std::string dir = cDir;
+  SystemTools::ConvertToUnixSlashes(dir);
+  std::string path = subdir;
+  do
+    {
+    path = SystemTools::GetParentDirectory(path.c_str());
+    if ( dir == path )
+      {
+      return true;
+      }
+    }
+  while ( path.size() > dir.size() );
+  return false;
+}
 
 // These must NOT be initialized.  Default initialization to zero is
 // necessary.
diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in
index e5881b05fc66904273e0c6fd10c9bd38bca48067..33e7904cafcb089780a745cf980e2c3063c4f813 100644
--- a/SystemTools.hxx.in
+++ b/SystemTools.hxx.in
@@ -316,6 +316,12 @@ public:
   static bool GetPermissions(const char* file, mode_t& mode);
   static bool SetPermissions(const char* file, mode_t mode);
 
+  /** Get the parent directory of the directory or file */
+  static std::string GetParentDirectory(const char* fileOrDir);
+
+  /** Check if the given file or directory is in subdirectory of dir */
+  static bool IsSubDirectory(const char* fileOrDir, const char* dir);
+
 protected:
   // these two functions can be called from ConvertToOutputPath
   /**