<div dir="ltr">The Windows implementation doesn't compile for me:<div><div>d:\src\llvm\lib\support\Windows/Path.inc(193) : error C2039: 'CreateSymbolicLinkW' : is not a member of '`global namespace''</div>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Mar 6, 2014 at 9:36 AM, Argyrios Kyrtzidis <span dir="ltr"><<a href="mailto:akyrtzi@gmail.com" target="_blank">akyrtzi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: akirtzidis<br>
Date: Thu Mar  6 11:36:46 2014<br>
New Revision: 203136<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=203136&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=203136&view=rev</a><br>
Log:<br>
[Support/FileSystem] Introduce llvm::sys::fs::create_symbolic_link().<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/Support/FileSystem.h<br>
    llvm/trunk/lib/Support/Unix/Path.inc<br>
    llvm/trunk/lib/Support/Windows/Path.inc<br>
<br>
Modified: llvm/trunk/include/llvm/Support/FileSystem.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=203136&r1=203135&r2=203136&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=203136&r1=203135&r2=203136&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)<br>
+++ llvm/trunk/include/llvm/Support/FileSystem.h Thu Mar  6 11:36:46 2014<br>
@@ -293,6 +293,14 @@ error_code create_directory(const Twine<br>
 ///          , otherwise a platform specific error_code.<br>
 error_code create_hard_link(const Twine &to, const Twine &from);<br>
<br>
+/// @brief Create a symbolic link from \a from to \a to.<br>
+///<br>
+/// @param to The path to link to.<br>
+/// @param from The path to link from. This is created.<br>
+/// @returns errc::success if successful<br>
+///          , otherwise a platform specific error_code.<br>
+error_code create_symbolic_link(const Twine &to, const Twine &from);<br>
+<br>
 /// @brief Get the current path.<br>
 ///<br>
 /// @param result Holds the current path on return.<br>
<br>
Modified: llvm/trunk/lib/Support/Unix/Path.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=203136&r1=203135&r2=203136&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=203136&r1=203135&r2=203136&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/Support/Unix/Path.inc (original)<br>
+++ llvm/trunk/lib/Support/Unix/Path.inc Thu Mar  6 11:36:46 2014<br>
@@ -285,6 +285,19 @@ error_code create_hard_link(const Twine<br>
   return error_code::success();<br>
 }<br>
<br>
+error_code create_symbolic_link(const Twine &to, const Twine &from) {<br>
+  // Get arguments.<br>
+  SmallString<128> from_storage;<br>
+  SmallString<128> to_storage;<br>
+  StringRef f = from.toNullTerminatedStringRef(from_storage);<br>
+  StringRef t = to.toNullTerminatedStringRef(to_storage);<br>
+<br>
+  if (::symlink(t.begin(), f.begin()) == -1)<br>
+    return error_code(errno, system_category());<br>
+<br>
+  return error_code::success();<br>
+}<br>
+<br>
 error_code remove(const Twine &path, bool IgnoreNonExisting) {<br>
   SmallString<128> path_storage;<br>
   StringRef p = path.toNullTerminatedStringRef(path_storage);<br>
<br>
Modified: llvm/trunk/lib/Support/Windows/Path.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=203136&r1=203135&r2=203136&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=203136&r1=203135&r2=203136&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/Support/Windows/Path.inc (original)<br>
+++ llvm/trunk/lib/Support/Windows/Path.inc Thu Mar  6 11:36:46 2014<br>
@@ -177,6 +177,25 @@ error_code create_hard_link(const Twine<br>
   return error_code::success();<br>
 }<br>
<br>
+error_code create_symbolic_link(const Twine &to, const Twine &from) {<br>
+  // Get arguments.<br>
+  SmallString<128> from_storage;<br>
+  SmallString<128> to_storage;<br>
+  StringRef f = from.toStringRef(from_storage);<br>
+  StringRef t = to.toStringRef(to_storage);<br>
+<br>
+  // Convert to utf-16.<br>
+  SmallVector<wchar_t, 128> wide_from;<br>
+  SmallVector<wchar_t, 128> wide_to;<br>
+  if (error_code ec = UTF8ToUTF16(f, wide_from)) return ec;<br>
+  if (error_code ec = UTF8ToUTF16(t, wide_to)) return ec;<br>
+<br>
+  if (!::CreateSymbolicLinkW(wide_from.begin(), wide_to.begin(), NULL))<br>
+    return windows_error(::GetLastError());<br>
+<br>
+  return error_code::success();<br>
+}<br>
+<br>
 error_code remove(const Twine &path, bool IgnoreNonExisting) {<br>
   SmallString<128> path_storage;<br>
   SmallVector<wchar_t, 128> path_utf16;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>