diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-03 07:41:25 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-03 07:41:25 +0000 |
commit | 9b391c513e0051289c7013dd9917eb6176724920 (patch) | |
tree | f4ee43d525bf4aa5c03dcdc6ea6d421d2b162634 /lib/Support/Windows | |
parent | d7b305f13ec1f53224c7eb8f4d3696eee5d10c40 (diff) | |
download | external_llvm-9b391c513e0051289c7013dd9917eb6176724920.zip external_llvm-9b391c513e0051289c7013dd9917eb6176724920.tar.gz external_llvm-9b391c513e0051289c7013dd9917eb6176724920.tar.bz2 |
Support/FileSystem: Add create_symlink implementation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120800 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Windows')
-rw-r--r-- | lib/Support/Windows/PathV2.inc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/Support/Windows/PathV2.inc b/lib/Support/Windows/PathV2.inc index d374dcc..b15f477 100644 --- a/lib/Support/Windows/PathV2.inc +++ b/lib/Support/Windows/PathV2.inc @@ -23,6 +23,15 @@ using namespace llvm; namespace { + typedef BOOLEAN (WINAPI *PtrCreateSymbolicLinkW)(
+ /*__in*/ LPCWSTR lpSymlinkFileName,
+ /*__in*/ LPCWSTR lpTargetFileName,
+ /*__in*/ DWORD dwFlags);
+
+ PtrCreateSymbolicLinkW create_symbolic_link_api = PtrCreateSymbolicLinkW(
+ ::GetProcAddress(::GetModuleHandleA("kernel32.dll"), + "CreateSymbolicLinkW")); + error_code UTF8ToUTF16(const StringRef &utf8, SmallVectorImpl<wchar_t> &utf16) { int len = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, @@ -220,6 +229,29 @@ error_code create_hard_link(const Twine &to, const Twine &from) { return make_error_code(errc::success); } +error_code create_symlink(const Twine &to, const Twine &from) { + // Only do it if the function is available at runtime. + if (!create_symbolic_link_api) + return make_error_code(errc::function_not_supported); + + // Get arguments. + SmallString<128> from_storage; + SmallString<128> to_storage; + StringRef f = from.toStringRef(from_storage); + StringRef t = to.toStringRef(to_storage); + + // Convert to utf-16. + SmallVector<wchar_t, 128> wide_from; + SmallVector<wchar_t, 128> wide_to; + if (error_code ec = UTF8ToUTF16(f, wide_from)) return ec; + if (error_code ec = UTF8ToUTF16(t, wide_to)) return ec; + + if (!create_symbolic_link_api(wide_from.begin(), wide_to.begin(), NULL)) + return make_error_code(windows_error(::GetLastError())); + + return make_error_code(errc::success); +} + error_code exists(const Twine &path, bool &result) { SmallString<128> path_storage; SmallVector<wchar_t, 128> path_utf16; |