C Programming/stdio.h/rename

rename is a function in the C programming language that renames a certain file.

The prototype of the function is:

Zero is returned upon success. Other integers are returned upon failure and  is set to an error code in this case.

The rename function is specified in the stdio.h library header file in C and the  header in C++. It is specified in ANSI C.

In POSIX, rename will fail (with EXDEV) if the old and new names are on different mounted file systems. If a call to rename succeeds it is guaranteed to have been atomic from the point of view of the current host (i.e., another program would only see the file with the old name or the file with the new name, not both or neither of them).

The Windows C library version of rename fails if the destination file already exists (POSIX would only fail if the user does not have permission to remove the destination file). Although the underlying WIN32 call has (since Win2K) had an option to replicate the POSIX atomic behavior, the library has never been fixed to use this.