...
If the file referenced by dest_file
exists prior to calling rename()
, the behavior is implementation-defined. On POSIX systems, the destination file is removed. On Windows systems, the rename()
fails.
This creates issues when trying to write portable code, or when trying to implement alternative behavior.
Protect Existing
...
Destination File
If the desired behavior is to ensure that any file referenced by dest_file
is not erased or overwritten, POSIX programmers must implement additional safeguards.
...