411 REFERENCE · Wikibooks
C programming/stdio.h/rename
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
rename is a function in the C programming language that renames a certain file.http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
ISO/IEC 9899:1999 specification
p. 268, § 7.19.4.2
The prototype of the function is:
int rename(const char *oldname, const char *newname)
Zero is returned upon success. Other integers are returned upon failure and errno 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 cstdio 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.sh rename SUS rename a file 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.
References
External links
C++ reference for std::rename
deep