diff options
author | Brad King <brad.king@kitware.com> | 2016-01-11 16:20:14 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-01-11 16:20:14 (GMT) |
commit | 9821924d45e0a9a22e8366060f41d6d87c26622f (patch) | |
tree | 3b79925255bbf16f234485644538676b74a5267b /Source/kwsys/SystemTools.cxx | |
parent | cedbb7994dddce2c3fdf846bf4563c846adf4632 (diff) | |
parent | 8e7356a2921c769c091c52140564b04108e692c4 (diff) | |
download | CMake-9821924d45e0a9a22e8366060f41d6d87c26622f.zip CMake-9821924d45e0a9a22e8366060f41d6d87c26622f.tar.gz CMake-9821924d45e0a9a22e8366060f41d6d87c26622f.tar.bz2 |
Merge branch 'upstream-KWSys' into update-kwsys
* upstream-KWSys:
KWSys 2016-01-11 (e8bf616e)
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 82087f0..e3428f8 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -4491,36 +4491,27 @@ bool SystemTools::FileIsFullPath(const char* in_name, size_t len) bool SystemTools::GetShortPath(const std::string& path, std::string& shortPath) { #if defined(_WIN32) && !defined(__CYGWIN__) - const int size = int(path.size()) +1; // size of return - char *tempPath = new char[size]; // create a buffer - DWORD ret; + std::string tempPath = path; // create a buffer // if the path passed in has quotes around it, first remove the quotes if (!path.empty() && path[0] == '"' && *path.rbegin() == '"') { - strcpy(tempPath,path.c_str()+1); - tempPath[size-2] = '\0'; - } - else - { - strcpy(tempPath,path.c_str()); + tempPath = path.substr(1, path.length()-2); } std::wstring wtempPath = Encoding::ToWide(tempPath); - std::vector<wchar_t> buffer(wtempPath.size()+1); - buffer[0] = 0; + DWORD ret = GetShortPathNameW(wtempPath.c_str(), NULL, 0); + std::vector<wchar_t> buffer(ret); ret = GetShortPathNameW(wtempPath.c_str(), - &buffer[0], static_cast<DWORD>(wtempPath.size())); + &buffer[0], static_cast<DWORD>(buffer.size())); - if(buffer[0] == 0 || ret > wtempPath.size()) + if (ret == 0) { - delete [] tempPath; return false; } else { shortPath = Encoding::ToNarrow(&buffer[0]); - delete [] tempPath; return true; } #else |