[llvm] r203136 - [Support/FileSystem] Introduce llvm::sys::fs::create_symbolic_link().
Reid Kleckner
rnk at google.com
Thu Mar 6 11:04:45 PST 2014
Takumi's bots agree:
http://bb.pgr.jp/builders/ninja-clang-i686-msc17-R/builds/7637
Symlinks were added in Vista. I don't believe LLVM has dropped support for
running on XP yet, so we can't use symlinks unconditionally. I also
thought you had to have admin to create symlinks on Vista, so they're
pretty hard to use anyway.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa363866(v=vs.85).aspx
On Thu, Mar 6, 2014 at 10:59 AM, Reid Kleckner <rnk at google.com> wrote:
> The Windows implementation doesn't compile for me:
> d:\src\llvm\lib\support\Windows/Path.inc(193) : error C2039:
> 'CreateSymbolicLinkW' : is not a member of '`global namespace''
>
>
> On Thu, Mar 6, 2014 at 9:36 AM, Argyrios Kyrtzidis <akyrtzi at gmail.com>wrote:
>
>> Author: akirtzidis
>> Date: Thu Mar 6 11:36:46 2014
>> New Revision: 203136
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=203136&view=rev
>> Log:
>> [Support/FileSystem] Introduce llvm::sys::fs::create_symbolic_link().
>>
>> Modified:
>> llvm/trunk/include/llvm/Support/FileSystem.h
>> llvm/trunk/lib/Support/Unix/Path.inc
>> llvm/trunk/lib/Support/Windows/Path.inc
>>
>> Modified: llvm/trunk/include/llvm/Support/FileSystem.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=203136&r1=203135&r2=203136&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/Support/FileSystem.h (original)
>> +++ llvm/trunk/include/llvm/Support/FileSystem.h Thu Mar 6 11:36:46 2014
>> @@ -293,6 +293,14 @@ error_code create_directory(const Twine
>> /// , otherwise a platform specific error_code.
>> error_code create_hard_link(const Twine &to, const Twine &from);
>>
>> +/// @brief Create a symbolic link from \a from to \a to.
>> +///
>> +/// @param to The path to link to.
>> +/// @param from The path to link from. This is created.
>> +/// @returns errc::success if successful
>> +/// , otherwise a platform specific error_code.
>> +error_code create_symbolic_link(const Twine &to, const Twine &from);
>> +
>> /// @brief Get the current path.
>> ///
>> /// @param result Holds the current path on return.
>>
>> Modified: llvm/trunk/lib/Support/Unix/Path.inc
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=203136&r1=203135&r2=203136&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Support/Unix/Path.inc (original)
>> +++ llvm/trunk/lib/Support/Unix/Path.inc Thu Mar 6 11:36:46 2014
>> @@ -285,6 +285,19 @@ error_code create_hard_link(const Twine
>> return error_code::success();
>> }
>>
>> +error_code create_symbolic_link(const Twine &to, const Twine &from) {
>> + // Get arguments.
>> + SmallString<128> from_storage;
>> + SmallString<128> to_storage;
>> + StringRef f = from.toNullTerminatedStringRef(from_storage);
>> + StringRef t = to.toNullTerminatedStringRef(to_storage);
>> +
>> + if (::symlink(t.begin(), f.begin()) == -1)
>> + return error_code(errno, system_category());
>> +
>> + return error_code::success();
>> +}
>> +
>> error_code remove(const Twine &path, bool IgnoreNonExisting) {
>> SmallString<128> path_storage;
>> StringRef p = path.toNullTerminatedStringRef(path_storage);
>>
>> Modified: llvm/trunk/lib/Support/Windows/Path.inc
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=203136&r1=203135&r2=203136&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Support/Windows/Path.inc (original)
>> +++ llvm/trunk/lib/Support/Windows/Path.inc Thu Mar 6 11:36:46 2014
>> @@ -177,6 +177,25 @@ error_code create_hard_link(const Twine
>> return error_code::success();
>> }
>>
>> +error_code create_symbolic_link(const Twine &to, const Twine &from) {
>> + // 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 (!::CreateSymbolicLinkW(wide_from.begin(), wide_to.begin(), NULL))
>> + return windows_error(::GetLastError());
>> +
>> + return error_code::success();
>> +}
>> +
>> error_code remove(const Twine &path, bool IgnoreNonExisting) {
>> SmallString<128> path_storage;
>> SmallVector<wchar_t, 128> path_utf16;
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140306/dcda0935/attachment.html>
More information about the llvm-commits
mailing list