[llvm] Support: unlock Windows API support, switch to Windows 10 RS1+ APIs (PR #102240)
Saleem Abdulrasool via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 10 11:13:08 PDT 2024
================
@@ -466,21 +466,41 @@ static std::error_code rename_internal(HANDLE FromHandle, const Twine &To,
(ToWide.size() * sizeof(wchar_t)));
FILE_RENAME_INFO &RenameInfo =
*reinterpret_cast<FILE_RENAME_INFO *>(RenameInfoBuf.data());
- RenameInfo.ReplaceIfExists = ReplaceIfExists;
- RenameInfo.RootDirectory = 0;
- RenameInfo.FileNameLength = ToWide.size() * sizeof(wchar_t);
- std::copy(ToWide.begin(), ToWide.end(), &RenameInfo.FileName[0]);
-
- SetLastError(ERROR_SUCCESS);
- if (!SetFileInformationByHandle(FromHandle, FileRenameInfo, &RenameInfo,
- RenameInfoBuf.size())) {
- unsigned Error = GetLastError();
- if (Error == ERROR_SUCCESS)
- Error = ERROR_CALL_NOT_IMPLEMENTED; // Wine doesn't always set error code.
- return mapWindowsError(Error);
+
+ static const struct RenameStyle {
+ DWORD dwFlag;
+ FILE_INFO_BY_HANDLE_CLASS Class;
+ } kRenameStyles[] = {
+ { FILE_RENAME_FLAG_POSIX_SEMANTICS, FileRenameInfoEx },
+ { 0, FileRenameInfo },
+ };
+
+ DWORD dwError = ERROR_SUCCESS;
+ for (const auto &style : kRenameStyles) {
+ RenameInfo.Flags = style.dwFlag |
+ (ReplaceIfExists ? FILE_RENAME_FLAG_REPLACE_IF_EXISTS
+ : 0);
+ RenameInfo.RootDirectory = 0;
+ RenameInfo.FileNameLength = ToWide.size() * sizeof(wchar_t);
+ std::copy(ToWide.begin(), ToWide.end(), &RenameInfo.FileName[0]);
+
+ SetLastError(ERROR_SUCCESS);
+ if (!SetFileInformationByHandle(FromHandle, FileRenameInfoEx, &RenameInfo,
----------------
compnerd wrote:
Whoops, thanks!
https://github.com/llvm/llvm-project/pull/102240
More information about the llvm-commits
mailing list