Atomic cross-rename of two paths

Since version v3.15 linux supports a file operation that will exchange any two directory entries atomically. This needs support of the filesystem so it’s not universal, but the commonly used filesystems can do it. The underlying syscall is renameat2 . Obligatory LWN article . #define _GNU_SOURCE #include <fcntl.h> #include <stdio.h> int renameat2 ( int olddirfd , const char * oldpath , int…