zig
zig copied to clipboard
std.windows: use atomic rename, if possible
trafficstars
Mitigates #14978.
As far as I understand, there are no tests currently. If wanted, I can add some to show that the posix behavior is what it claims.
Closing abandoned pull request. Please open a new one if you wish to continue this work.
Found it in mingw64 upstream via rg '.*FILE_RENAME.*': mingw-w64-headers/include/winbase.h:3122
#if _WIN32_WINNT >= _WIN32_WINNT_WIN10_RS1
#define FILE_RENAME_FLAG_REPLACE_IF_EXISTS 0x00000001
#define FILE_RENAME_FLAG_POSIX_SEMANTICS 0x00000002
#endif
#if _WIN32_WINNT >= _WIN32_WINNT_WIN10_RS3
#define FILE_RENAME_FLAG_SUPPRESS_PIN_STATE_INHERITANCE 0x00000004
#endif
typedef struct _FILE_RENAME_INFO {
#if _WIN32_WINNT >= _WIN32_WINNT_WIN10_RS1
__C89_NAMELESS union {
BOOLEAN ReplaceIfExists;
DWORD Flags;
};
#else
BOOLEAN ReplaceIfExists;
#endif
HANDLE RootDirectory;
DWORD FileNameLength;
WCHAR FileName[1];
} FILE_RENAME_INFO,*PFILE_RENAME_INFO;
I'll probably make a PR next weekend unless somebody else is faster.