What does "swap filenames" mean? Are you talking about the file system, or just variables in your program?
If your program is C++, and you have two filenames in strings, and want to swap them, use std::swap. This only changes the variables in the program:
std::string filenameA("somefilename");
std::string filenameB("othername");
std::swap(filenameA, filenameB);
std::cout << filenameA << std::endl; // prints "othername"
If you have two files on the disk, and you want the names to swap content with each other, then no, there's no way to easily to that, if you want to preserve hard links. If you just want to perform a "safe save," then the unix rename() system call will clobber the destination file with the source file in an atomic operation (as atomic as can be supported by the underlying filesystem). Thus, you'd safe-save like this:
std::string savename(filename);
savename += ".tmp";
... write data to savename ...
if (::rename(savename.c_str(), filename.c_str())
If you really, truly need to swap the files on disk (say, to keep a backup copy), then enter hard-linking. Note: hard-linking isn't supported on all file systems (specifically some SMB file shares), so you'll need to implement some backup if needed. You will need a temporary file name, but not any temporary data store. While you can implement it manually with link() and unlink() (remember: files can have multiple hard links in UNIX), it's easier just using rename(). You can't do a swap entirely atomically, though.
assuming oldfile is "filname.dat" and newfile is "filename.dat.bak" you'll get this:
::link(oldfile, tempfile);
::rename(newfile, oldfile);
::rename(tempfile, newfile);
If you crash after the link, you'll have the new data in newfile, and the old data in oldfile and tempfile.
If you crash after the first rename, you'll have the new data in oldfile, and the old data in tempfile (but not newfile!)