Getting back to Philipp's original bug report, Apple documentation says macOS has a facility like the Linux renameat2 system call (i.e., it's like 'renameat' except it can be told to fail if the destination already exists). Attached is a proposed patch to use this facility, which means that the case-insensitivity test would no longer need to be done in macOS. If there's some way to implement renameat_noreplace on MS-Windows we could get rid of the case-insensitivity test there too. I don't have easy access to macOS so I have not installed this patch. It'd be nice, Philipp, if you could try it out. This patch is independent of the destination-directory patch that I recently proposed in: https://bugs.gnu.org/27986#14