[libcxx-commits] [PATCH] D91170: [15/N] [libcxx] Implement the canonical function for windows
    Martin Storsjö via Phabricator via libcxx-commits 
    libcxx-commits at lists.llvm.org
       
    Tue Nov 10 08:36:46 PST 2020
    
    
  
mstorsjo created this revision.
mstorsjo added a reviewer: libc++.
Herald added a project: libc++.
Herald added 1 blocking reviewer(s): libc++.
mstorsjo requested review of this revision.
Repository:
  rG LLVM Github Monorepo
https://reviews.llvm.org/D91170
Files:
  libcxx/src/filesystem/operations.cpp
Index: libcxx/src/filesystem/operations.cpp
===================================================================
--- libcxx/src/filesystem/operations.cpp
+++ libcxx/src/filesystem/operations.cpp
@@ -780,6 +780,21 @@
   if (hold.get() == nullptr)
     return err.report(capture_errno());
   return {hold.get()};
+#elif defined(_LIBCPP_WIN32API)
+  wchar_t ret[MAX_PATH];
+  detail::WinHandle h(p.c_str(), FILE_READ_ATTRIBUTES, 0);
+  if (!h)
+    return err.report(detail::capture_last_error());
+  if (!GetFinalPathNameByHandleW(h, ret, MAX_PATH,
+                                 FILE_NAME_NORMALIZED | VOLUME_NAME_DOS))
+    return err.report(detail::capture_last_error());
+  if (!wcsncmp(ret, L"\\\\?\\", 4)) {
+    if (ret[5] == ':') // \\?\X: -> X:
+      return {&ret[4]};
+    if (!wcsncmp(&ret[4], L"UNC\\", 4)) // \\?\UNC\server -> \\server
+      return {std::wstring(L"\\\\") + &ret[8]};
+  }
+  return {ret};
 #else
   char buff[PATH_MAX + 1];
   char* ret;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91170.304206.patch
Type: text/x-patch
Size: 970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201110/cbc5184f/attachment.bin>
    
    
More information about the libcxx-commits
mailing list