diff options
author | KWSys Robot <kwrobot@kitware.com> | 2015-02-25 14:31:23 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-02-26 13:54:37 (GMT) |
commit | 5e2b418f7b0083b01004910848eb4823ea014ec1 (patch) | |
tree | 9a31e1aac5bf508d6de35c32b0bc0e019e756356 /SystemTools.cxx | |
parent | 0b9aad7568bc5f1cf56e01fe2b3dc57f5dff5133 (diff) | |
download | CMake-5e2b418f7b0083b01004910848eb4823ea014ec1.zip CMake-5e2b418f7b0083b01004910848eb4823ea014ec1.tar.gz CMake-5e2b418f7b0083b01004910848eb4823ea014ec1.tar.bz2 |
KWSys 2015-02-25 (1b75ad3d)
Extract upstream KWSys using the following shell commands.
$ git archive --prefix=upstream-kwsys/ 1b75ad3d | tar x
$ git shortlog --no-merges --abbrev=8 --format='%h %s' d4e7f08e..1b75ad3d
Domen Vrankar (3):
2b042ff6 SystemTools: Optionally report error from GetRealPath
7c9a970a Glob: Remove dead code
1b75ad3d Glob: Remove addition of extra '/'
Change-Id: I04ac5aa4748925bc953db0abff2d4418080882b5
Diffstat (limited to 'SystemTools.cxx')
-rw-r--r-- | SystemTools.cxx | 58 |
1 files changed, 52 insertions, 6 deletions
diff --git a/SystemTools.cxx b/SystemTools.cxx index 2708211..bf6f458 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -250,17 +250,46 @@ inline int Chdir(const kwsys_stl::string& dir) return _wchdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str()); #endif } -inline void Realpath(const kwsys_stl::string& path, kwsys_stl::string & resolved_path) +inline void Realpath(const kwsys_stl::string& path, + kwsys_stl::string& resolved_path, + kwsys_stl::string* errorMessage = 0) { kwsys_stl::wstring tmp = KWSYS_NAMESPACE::Encoding::ToWide(path); wchar_t *ptemp; wchar_t fullpath[MAX_PATH]; - if( GetFullPathNameW(tmp.c_str(), sizeof(fullpath)/sizeof(fullpath[0]), - fullpath, &ptemp) ) + DWORD bufferLen = GetFullPathNameW(tmp.c_str(), + sizeof(fullpath) / sizeof(fullpath[0]), + fullpath, &ptemp); + if( bufferLen < sizeof(fullpath)/sizeof(fullpath[0]) ) { resolved_path = KWSYS_NAMESPACE::Encoding::ToNarrow(fullpath); KWSYS_NAMESPACE::SystemTools::ConvertToUnixSlashes(resolved_path); } + else if(errorMessage) + { + if(bufferLen) + { + *errorMessage = "Destination path buffer size too small."; + } + else if(unsigned int errorId = GetLastError()) + { + LPSTR message = NULL; + DWORD size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER + | FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, errorId, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR)&message, 0, NULL); + *errorMessage = std::string(message, size); + LocalFree(message); + } + else + { + *errorMessage = "Unknown error."; + } + + resolved_path = ""; + } else { resolved_path = path; @@ -287,15 +316,31 @@ inline int Chdir(const kwsys_stl::string& dir) { return chdir(dir.c_str()); } -inline void Realpath(const kwsys_stl::string& path, kwsys_stl::string & resolved_path) +inline void Realpath(const kwsys_stl::string& path, + kwsys_stl::string& resolved_path, + kwsys_stl::string* errorMessage = 0) { char resolved_name[KWSYS_SYSTEMTOOLS_MAXPATH]; + errno = 0; char *ret = realpath(path.c_str(), resolved_name); if(ret) { resolved_path = ret; } + else if(errorMessage) + { + if(errno) + { + *errorMessage = strerror(errno); + } + else + { + *errorMessage = "Unknown error."; + } + + resolved_path = ""; + } else { // if path resolution fails, return what was passed in @@ -3046,10 +3091,11 @@ kwsys_stl::string SystemTools return ""; } -kwsys_stl::string SystemTools::GetRealPath(const kwsys_stl::string& path) +kwsys_stl::string SystemTools::GetRealPath(const kwsys_stl::string& path, + kwsys_stl::string* errorMessage) { kwsys_stl::string ret; - Realpath(path, ret); + Realpath(path, ret, errorMessage); return ret; } |