I have two files,
You can use the (fairly recent) linux syscall
Here is the definition :
int renameat2(int olddir, const char *oldname, int newdir, const char *newname, unsigned int flags);
You can find its source code on the kernel's Git repo if needed.
It's basically the same as
renameat, but if you pass the flag RENAME_EXCHANGE it will swap the two files instead of renaming one into the other.
The operation is atomic.