I would assume that in the following snippet of code, the file would be renamed to the temporary file, and then disappear once execution is complete. But it doesn't work like that, and the executable still exists after being run.
Shouldn't the file be able to be renamed while running?
#include <iostream>
int main(int argc_, char** argv_)
{
char rename_path_buffer[L_tmpnam_s];
tmpnam_s(rename_path_buffer, L_tmpnam_s);
rename(argv_[0], rename_path_buffer);
}
The file is locked against renaming while it is being executed.
Try to manually rename it while it is running, and you will get a corresponding error message; or check the return value of the rename function.