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 | 32ef4d2e1bff1a23d42a7dfa0a5d248344b6c47e (patch) | |
tree | 20850c7aae0532cfbbb2f0cd69e7347bc2673002 /llvm/lib | |
parent | 513f1b666f3b36bdcb5c3eed5061a19678f53e53 (diff) | |
download | bcm5719-llvm-32ef4d2e1bff1a23d42a7dfa0a5d248344b6c47e.tar.gz bcm5719-llvm-32ef4d2e1bff1a23d42a7dfa0a5d248344b6c47e.zip |
Support/FileSystem: Implement canonicalize.
llvm-svn: 146363
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Support/Unix/PathV2.inc | 7 | ||||
-rw-r--r-- | llvm/lib/Support/Windows/PathV2.inc | 38 | ||||
-rw-r--r-- | llvm/lib/Support/Windows/Windows.h | 20 |
3 files changed, 65 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/PathV2.inc b/llvm/lib/Support/Unix/PathV2.inc index 7477b4f2a08..41ed49fec7d 100644 --- a/llvm/lib/Support/Unix/PathV2.inc +++ b/llvm/lib/Support/Unix/PathV2.inc @@ -439,6 +439,13 @@ rety_open_create: return success; } +error_code canonicalize(const Twine &path, SmallVectorImpl<char> &result) { + // Paths are already canonicalized on posix systems. + assert(path::is_absolute(path) && "path must be absolute!"); + path.toVector(result); + return success; +} + error_code detail::directory_iterator_construct(detail::DirIterState &it, StringRef path){ SmallString<128> path_null(path); diff --git a/llvm/lib/Support/Windows/PathV2.inc b/llvm/lib/Support/Windows/PathV2.inc index afb5533dc82..abb53c2ce18 100644 --- a/llvm/lib/Support/Windows/PathV2.inc +++ b/llvm/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; diff --git a/llvm/lib/Support/Windows/Windows.h b/llvm/lib/Support/Windows/Windows.h index 5c1da0d617a..27540750355 100644 --- a/llvm/lib/Support/Windows/Windows.h +++ b/llvm/lib/Support/Windows/Windows.h @@ -128,6 +128,24 @@ struct FindHandleTraits : CommonHandleTraits { } }; +struct FileMappingHandleTraits : CommonHandleTraits { + static handle_type GetInvalid() { + return 0; + } +}; + +struct MappedViewOfFileHandleTraits : CommonHandleTraits { + typedef LPVOID handle_type; + + static handle_type GetInvalid() { + return 0; + } + + static void Close(handle_type h) { + ::UnmapViewOfFile(h); + } +}; + struct FileHandleTraits : CommonHandleTraits {}; typedef ScopedHandle<CommonHandleTraits> ScopedCommonHandle; @@ -135,6 +153,8 @@ typedef ScopedHandle<FileHandleTraits> ScopedFileHandle; typedef ScopedHandle<CryptContextTraits> ScopedCryptContext; typedef ScopedHandle<FindHandleTraits> ScopedFindHandle; typedef ScopedHandle<JobHandleTraits> ScopedJobHandle; +typedef ScopedHandle<FileMappingHandleTraits> ScopedFileMappingHandle; +typedef ScopedHandle<MappedViewOfFileHandleTraits> ScopedMappedViewOfFileHandle; namespace llvm { template <class T> |