diff --git a/SystemTools.cxx b/SystemTools.cxx
index 3c4a36221f1da350d4d4ceb05f47837e8e6e4e4f..2bc87185af8ffa52030f76121e045054fa87eb95 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -89,6 +89,18 @@ public:
 #include <io.h>
 #include <direct.h>
 #define _unlink unlink
+#endif 
+
+/* The maximum length of a file name.  */
+#if defined(PATH_MAX)
+# define KWSYS_SYSTEMTOOLS_MAXPATH PATH_MAX
+#elif defined(MAXPATHLEN)
+# define KWSYS_SYSTEMTOOLS_MAXPATH MAXPATHLEN
+#else
+# define KWSYS_SYSTEMTOOLS_MAXPATH 16384
+#endif
+
+#if defined(_WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__))
 inline int Mkdir(const char* dir)
 {
   return _mkdir(dir);
@@ -141,15 +153,7 @@ inline int Chdir(const char* dir)
 }
 inline void Realpath(const char *path, kwsys_stl::string & resolved_path)
 {
-# ifdef MAXPATHLEN
-  char resolved_name[MAXPATHLEN];
-# else
-#  ifdef PATH_MAX
-  char resolved_name[PATH_MAX];
-#  else
-  char resolved_name[5024];
-#  endif  //PATH_MAX
-# endif //MAXPATHLEN
+  char resolved_name[KWSYS_SYSTEMTOOLS_MAXPATH];
 
   realpath(path, resolved_name);
   resolved_path = resolved_name;
@@ -196,6 +200,7 @@ class SystemToolsTranslationMap :
 {
 };
 
+
 double
 SystemTools::GetTime(void)
 {
@@ -1848,6 +1853,13 @@ bool SystemTools::RemoveADirectory(const char* source)
   return (Rmdir(source) == 0);
 }
 
+/**
+ */
+size_t SystemTools::GetMaximumFilePathLength()
+{
+  return KWSYS_SYSTEMTOOLS_MAXPATH;
+}
+
 /**
  * Find the file the given name.  Searches the given path and then
  * the system search path.  Returns the full path to the file if it is
diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in
index f2b56e14cd4b7b1e4afcd4e3bb8de5fa8294330d..5c73b27e9422d4c7b120367bfcfe81e6bef90064 100644
--- a/SystemTools.hxx.in
+++ b/SystemTools.hxx.in
@@ -472,6 +472,11 @@ public:
    */
   static bool RemoveADirectory(const char* source);
 
+  /**
+   * Get the maximum full file path length
+   */
+  static size_t GetMaximumFilePathLength();
+
   /**
    * Find a file in the system PATH, with optional extra paths
    */