diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2011-12-12 06:04:01 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2011-12-12 06:04:01 +0000 |
commit | c3b00e80400d27d5d6152374d87c0ad5866c780c (patch) | |
tree | 3adf92cdfd9478aae132d0d0d2ab5f25b57a79ed /lib/Support/Windows/PathV2.inc | |
parent | 1dd2ee7bf4d848e368829cb01033f297afb674ab (diff) |
Support/FileSystem: Implement canonicalize.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146363 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Windows/PathV2.inc')
-rw-r--r-- | lib/Support/Windows/PathV2.inc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/Support/Windows/PathV2.inc b/lib/Support/Windows/PathV2.inc index afb5533dc8..abb53c2ce1 100644 --- a/lib/Support/Windows/PathV2.inc +++ b/lib/Support/Windows/PathV2.inc @@ -638,6 +638,44 @@ retry_create_file: return success; } +error_code canonicalize(const Twine &path, SmallVectorImpl<char> &result) { + assert(path::is_absolute(path) && "path must be absolute!"); + SmallString<128> path_storage; + StringRef p = path.toStringRef(path_storage); + SmallVector<wchar_t, 128> path_utf16; + result.set_size(0); + + // Convert path to UTF-16. + if (error_code ec = UTF8ToUTF16(p, path_utf16)) + return ec; + + DWORD size = ::GetShortPathNameW(c_str(path_utf16), NULL, 0); + SmallVector<wchar_t, 128> short_path; + short_path.reserve(size + 1); + size = ::GetShortPathNameW( c_str(path_utf16) + , short_path.data() + , short_path.capacity()); + if (!size) + return windows_error(::GetLastError()); + + short_path.set_size(size); + + size = ::GetLongPathNameW(c_str(short_path), NULL, 0); + path_utf16.reserve(size + 1); + size = ::GetLongPathNameW( c_str(short_path) + , path_utf16.data() + , path_utf16.capacity()); + if (!size) + return windows_error(::GetLastError()); + + path_utf16.set_size(size); + + if (error_code ec = UTF16ToUTF8(path_utf16.data(), path_utf16.size(), result)) + return ec; + + return success; +} + error_code get_magic(const Twine &path, uint32_t len, SmallVectorImpl<char> &result) { SmallString<128> path_storage; |