summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemTools.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r--Source/kwsys/SystemTools.cxx86
1 files changed, 65 insertions, 21 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 9b7a6ed..fe0e31b 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -65,10 +65,15 @@
#endif
// Windows API. Some parts used even on cygwin.
-#if defined(_WIN32)
+#if defined(_WIN32) || defined (__CYGWIN__)
# include <windows.h>
#endif
+#ifdef __CYGWIN__
+# undef _WIN32
+extern "C" void cygwin_conv_to_win32_path(const char *path, char *win32_path);
+#endif
+
// getpwnam doesn't exist on Windows and Cray Xt3/Catamount
// same for TIOCGWINSZ
#if defined(_WIN32) || defined (__LIBCATAMOUNT__)
@@ -892,39 +897,69 @@ bool SystemTools::SameFile(const char* file1, const char* file2)
#endif
}
-
-// return true if the file exists
-bool SystemTools::FileExists(const char* filename, bool isFile)
+//----------------------------------------------------------------------------
+#if defined(_WIN32) || defined(__CYGWIN__)
+static bool WindowsFileExists(const char* filename)
{
-#ifdef _MSC_VER
-# define access _access
-#endif
-#ifndef R_OK
-# define R_OK 04
+ WIN32_FILE_ATTRIBUTE_DATA fd;
+ return GetFileAttributesExA(filename, GetFileExInfoStandard, &fd) != 0;
+}
#endif
-#ifdef __SYLLABLE__
- if ((filename !=0) && (*filename == 0))
+//----------------------------------------------------------------------------
+bool SystemTools::FileExists(const char* filename)
+{
+ if(!(filename && *filename))
{
return false;
- }
+ }
+#if defined(__CYGWIN__)
+ // Convert filename to native windows path if possible.
+ char winpath[MAX_PATH];
+ if(SystemTools::PathCygwinToWin32(filename, winpath))
+ {
+ return WindowsFileExists(winpath);
+ }
+ return access(filename, R_OK) == 0;
+#elif defined(_WIN32)
+ return WindowsFileExists(filename);
+#else
+ return access(filename, R_OK) == 0;
#endif
+}
- if ( access(filename, R_OK) != 0 )
+//----------------------------------------------------------------------------
+bool SystemTools::FileExists(const char* filename, bool isFile)
+{
+ if(SystemTools::FileExists(filename))
{
- return false;
+ // If isFile is set return not FileIsDirectory,
+ // so this will only be true if it is a file
+ return !isFile || !SystemTools::FileIsDirectory(filename);
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------
+#ifdef __CYGWIN__
+bool SystemTools::PathCygwinToWin32(const char *path, char *win32_path)
+{
+ SystemToolsTranslationMap::iterator i =
+ SystemTools::Cyg2Win32Map->find(path);
+
+ if (i != SystemTools::Cyg2Win32Map->end())
+ {
+ strncpy(win32_path, i->second.c_str(), MAX_PATH);
}
else
{
- // If isFile is set return not FileIsDirectory,
- // so this will only be true if it is a file
- if(isFile)
- {
- return !SystemTools::FileIsDirectory(filename);
- }
- return true;
+ cygwin_conv_to_win32_path(path, win32_path);
+ SystemToolsTranslationMap::value_type entry(path, win32_path);
+ SystemTools::Cyg2Win32Map->insert(entry);
}
+ return win32_path[0] != 0;
}
+#endif
bool SystemTools::Touch(const char* filename, bool create)
{
@@ -4536,6 +4571,9 @@ bool SystemTools::ParseURL( const kwsys_stl::string& URL,
unsigned int SystemToolsManagerCount;
SystemToolsTranslationMap *SystemTools::TranslationMap;
SystemToolsTranslationMap *SystemTools::LongPathMap;
+#ifdef __CYGWIN__
+SystemToolsTranslationMap *SystemTools::Cyg2Win32Map;
+#endif
// SystemToolsManager manages the SystemTools singleton.
// SystemToolsManager should be included in any translation unit
@@ -4581,6 +4619,9 @@ void SystemTools::ClassInitialize()
// Allocate the translation map first.
SystemTools::TranslationMap = new SystemToolsTranslationMap;
SystemTools::LongPathMap = new SystemToolsTranslationMap;
+#ifdef __CYGWIN__
+ SystemTools::Cyg2Win32Map = new SystemToolsTranslationMap;
+#endif
// Add some special translation paths for unix. These are not added
// for windows because drive letters need to be maintained. Also,
@@ -4637,6 +4678,9 @@ void SystemTools::ClassFinalize()
{
delete SystemTools::TranslationMap;
delete SystemTools::LongPathMap;
+#ifdef __CYGWIN__
+ delete SystemTools::Cyg2Win32Map;
+#endif
}