[PATCH] D13536: Fixed sys::findProgramByName (Windows) to accept files with point in name

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 7 14:46:28 PDT 2015


grimar created this revision.
grimar added a reviewer: rnk.
grimar added subscribers: llvm-commits, grimar.

Problem was in SearchPathW function that does not attach an extension if file already has one.
That does not work for executables like ld.lld2 for example which requre to has .exe extension but SearchPath thinks that its "lld2". 
So for such cases I added the extension manually and ignore the extension argument.

Not sure who should review it.

http://reviews.llvm.org/D13536

Files:
  Program.inc

Index: Program.inc
===================================================================
--- Program.inc
+++ Program.inc
@@ -75,9 +75,26 @@
 
     do {
       U16Result.reserve(Len);
-      Len = ::SearchPathW(Path, c_str(U16Name),
-                          U16Ext.empty() ? nullptr : c_str(U16Ext),
-                          U16Result.capacity(), U16Result.data(), nullptr);
+      auto I = std::find_end(U16Name.begin(), U16Name.end(), U16Ext.begin(),
+                             U16Ext.end());
+      // if has this extension at the end
+      if (I != U16Name.end() && (I + U16Ext.size()) == U16Name.end()) {
+        Len = ::SearchPathW(Path, c_str(U16Name), nullptr, U16Result.capacity(),
+                            U16Result.data(), nullptr);
+      } else {
+        // if no - lets attach the extension. That branch is needed for files
+        // with a point in name like aaa.bbb. SearchPathW will not add extension
+        // from its argument to such files and that is a problem sometimes. So
+        // we need to add extension manually.
+        SmallVector<wchar_t, MAX_PATH> U16NameExt;
+        if (std::error_code EC =
+                windows::UTF8ToUTF16(Twine(Name + Ext).str(), U16NameExt))
+          return EC;
+
+        Len = ::SearchPathW(Path, c_str(U16NameExt), nullptr,
+                            U16Result.capacity(), U16Result.data(), nullptr);
+      }
+
     } while (Len > U16Result.capacity());
 
     if (Len != 0)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13536.36799.patch
Type: text/x-patch
Size: 1461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151007/07cb678e/attachment.bin>


More information about the llvm-commits mailing list