c Programming/C Reference/stdio.h/rename
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. 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.
- ISO/IEC 9899:1999 specification. p. 268, § 22.214.171.124. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf.
- The Single UNIX® Specification, Issue 7 from The Open Group: rename a file – System Interfaces Reference,
Read in another language
This page is available in 1 language