Alas, yes -- seems like my idea was correct. Using perror() I could see "Permission denied" as error message.
Is there any way to circumvent this? I know for a fact nobody uses the file because it is generated and closed in my app way before the renaming takes place.
Calling a C function to do it does not trump user permissions or other OS-specific conditions. (For example, if you are on Windows the rename() function may fail if the target file already exists, instead of overwriting it as it is supposed to... a known bug.)
The best way to handle this kind of stuff is to check that everything is where they are supposed to be (or not be) before beginning, check permissions, rename, then check again to see if things are what they should have become.
Thank you both Sammy34 and Duoas, it seems the problem is related to my application! (Thread opening/closing file deals incorrectly with the closing part).