[PATCH] D113264: [clang] [DirectoryWatcher] Remove leading \\?\ from GetFinalPathNameByHandleW

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 8 12:22:14 PST 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2ca6fc34fc08: [clang] [DirectoryWatcher] Remove leading \\?\ from GetFinalPathNameByHandleW (authored by mstorsjo).

Changed prior to commit:
  https://reviews.llvm.org/D113264?vs=385025&id=385591#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113264/new/

https://reviews.llvm.org/D113264

Files:
  clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp


Index: clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
===================================================================
--- clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
+++ clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
@@ -88,10 +88,15 @@
   // handle to the watcher and performing synchronous operations.
   {
     DWORD Size = GetFinalPathNameByHandleW(DirectoryHandle, NULL, 0, 0);
-    std::unique_ptr<WCHAR[]> Buffer{new WCHAR[Size]};
+    std::unique_ptr<WCHAR[]> Buffer{new WCHAR[Size + 1]};
     Size = GetFinalPathNameByHandleW(DirectoryHandle, Buffer.get(), Size, 0);
     Buffer[Size] = L'\0';
-    llvm::sys::windows::UTF16ToUTF8(Buffer.get(), Size, Path);
+    WCHAR *Data = Buffer.get();
+    if (Size >= 4 && ::memcmp(Data, L"\\\\?\\", 8) == 0) {
+      Data += 4;
+      Size -= 4;
+    }
+    llvm::sys::windows::UTF16ToUTF8(Data, Size, Path);
   }
 
   size_t EntrySize = sizeof(FILE_NOTIFY_INFORMATION) + MAX_PATH * sizeof(WCHAR);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113264.385591.patch
Type: text/x-patch
Size: 1006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211108/6655cf0a/attachment.bin>


More information about the cfe-commits mailing list