[llvm] Support: unlock Windows API support, switch to Windows 10 RS1+ APIs (PR #102240)
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 10 14:02:39 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 {
+ DWORD dwFlag;
+ FILE_INFO_BY_HANDLE_CLASS Class;
+ } kRenameStyles[] = {
+ { FILE_RENAME_FLAG_POSIX_SEMANTICS, FileRenameInfoEx },
+ { 0, FileRenameInfo },
+ };
+
+ for (const auto &style : kRenameStyles) {
+ RenameInfo.Flags = style.dwFlag |
+ (ReplaceIfExists ? FILE_RENAME_FLAG_REPLACE_IF_EXISTS
+ : 0);
----------------
mstorsjo wrote:
This way of setting the flags, in what is a union in `FILE_RENAME_INFO` doesn't seem right for the old version; we should be setting `RenameInfo.ReplaceIfExists = ReplaceIfExists;` in that case. Writing to `Flags` which is aliased with `ReplaceIfExists` might work somehow, but we should be passing in the value `ReplaceIfExists` (and nothing else in that case) - and it doesn't feel entirely kosher to set a union field via another field. (I don't remember exactly, this may be a case which is ok in C but invalid in C++.)
https://github.com/llvm/llvm-project/pull/102240
More information about the llvm-commits
mailing list