diff options
author | KWSys Upstream <kwrobot@kitware.com> | 2016-08-03 16:32:48 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-08-04 14:11:06 (GMT) |
commit | 6c0820a8748e24155d3b7ce6991a90f5a396f524 (patch) | |
tree | a73fc87560b8d3b6c22c7da819ff3a45ef171e69 /SystemTools.cxx | |
parent | 3e6ec47c421808123efac2cf67850f8b75839c67 (diff) | |
download | CMake-6c0820a8748e24155d3b7ce6991a90f5a396f524.zip CMake-6c0820a8748e24155d3b7ce6991a90f5a396f524.tar.gz CMake-6c0820a8748e24155d3b7ce6991a90f5a396f524.tar.bz2 |
KWSys 2016-08-03 (6d23dd7e)
Code extracted from:
http://public.kitware.com/KWSys.git
at commit 6d23dd7e455a7b2088c4ec6dce760d8243b84ee6 (master).
Upstream Shortlog
-----------------
Ben Boeckel (1):
6d23dd7e SystemTools: add a PathExists method
Diffstat (limited to 'SystemTools.cxx')
-rw-r--r-- | SystemTools.cxx | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/SystemTools.cxx b/SystemTools.cxx index d479ee1..eb2bec6 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -1292,6 +1292,32 @@ bool SystemTools::SameFile(const std::string& file1, const std::string& file2) } //---------------------------------------------------------------------------- +bool SystemTools::PathExists(const std::string& path) +{ + if(path.empty()) + { + return false; + } +#if defined(__CYGWIN__) + // Convert path to native windows path if possible. + char winpath[MAX_PATH]; + if(SystemTools::PathCygwinToWin32(path.c_str(), winpath)) + { + return (GetFileAttributesA(winpath) != INVALID_FILE_ATTRIBUTES); + } + struct stat st; + return lstat(path.c_str(), &st) == 0; +#elif defined(_WIN32) + return (GetFileAttributesW( + SystemTools::ConvertToWindowsExtendedPath(path).c_str()) + != INVALID_FILE_ATTRIBUTES); +#else + struct stat st; + return lstat(path.c_str(), &st) == 0; +#endif +} + +//---------------------------------------------------------------------------- bool SystemTools::FileExists(const char* filename) { if(!filename) |