[PATCH] D38817: Support: Work around missing SetFileInformationByHandle on Wine

Hans Wennborg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 11 13:09:38 PDT 2017


hans created this revision.

In r315079, fs::rename was reimplemented in terms of CreateFile and SetFileInformationByHandle. Unfortunately, the latter isn't supported by Wine. This adds a horrible fallback to MoveFileEx for that case.


https://reviews.llvm.org/D38817

Files:
  lib/Support/Windows/Path.inc


Index: lib/Support/Windows/Path.inc
===================================================================
--- lib/Support/Windows/Path.inc
+++ lib/Support/Windows/Path.inc
@@ -384,6 +384,19 @@
   return std::error_code();
 }
 
+static bool is_wine() {
+  static bool Initialized = false;
+  static bool IsWine = false;
+
+  if (!Initialized) {
+    if (HMODULE ntdll = ::GetModuleHandleA("ntdll.dll"))
+      IsWine = ::GetProcAddress(ntdll, "wine_get_version");
+    Initialized = true;
+  }
+
+  return IsWine;
+}
+
 std::error_code rename(const Twine &From, const Twine &To) {
   // Convert to utf-16.
   SmallVector<wchar_t, 128> WideFrom;
@@ -393,6 +406,13 @@
   if (std::error_code EC = widenPath(To, WideTo))
     return EC;
 
+  if (is_wine()) {
+    // Wine doesn't support SetFileInformationByHandle used below.
+    if (::MoveFileExW(WideFrom.begin(), WideTo.begin(), MOVEFILE_REPLACE_EXISTING))
+      return std::error_code();
+    return mapWindowsError(GetLastError());
+  }
+
   ScopedFileHandle FromHandle;
   // Retry this a few times to defeat badly behaved file system scanners.
   for (unsigned Retry = 0; Retry != 200; ++Retry) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38817.118674.patch
Type: text/x-patch
Size: 1150 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171011/96ce7206/attachment.bin>


More information about the llvm-commits mailing list