Now find a way to do that *without* the need for a temporary file, and you might have something relevant to contribute to the thread.
A temporary file is not always an acceptable option; it presumes that you know of a directory in which you can create a temporary file guaranteed to be on the same filesystem as the file that it's replacing, so that rename() can be implemented atomically, and that either there are no hard links to the file or that those links should be broken by the rename(). Moreover, the rename() method resets portions of the security context of the original file, including ownership and security labels, which you can't restore without superuser capabilities.
This thread exists because people who do know plenty about the POSIX interfaces also know that they don't provide a general solution.