|
|
#include <stdio.h>int rename (old, new) const char *old; const char *new;
The rename function causes the file or directory whose pathname is the string pointed to by old to be henceforth known by the pathname given by the string pointed to by new. The file or directory named old is effectively removed. If a file or directory named by the string pointed to by new exists prior to the call to the rename function, new is removed.
If the old argument and the new argument both refer to links to the same existing file, the rename function returns successfully and performs no other action.
The old and the new arguments must both point to the pathname of a file or they must both point to the pathname of a directory. If the link named by the new argument exists, it is removed and old renamed to new. In this case, a link named new exists throughout the the renaming operation and refers either to the file referred to by new or old before the operation began. Write access permission is required for both the directory containing old and the directory containing new.
If the old argument points to the pathname of a directory, the new argument cannot point to the pathname of a file. If the directory named by the new argument exists, it is removed and old renamed to new. In this case, a link named new exists throughout the renaming operation and refers either to the file referred to by new or old before the operation began. Thus, if new names an existing directory, it is required to be an empty directory.
The new pathname cannot contain a path prefix that names old. Write access permission is required for the directory containing old and the directory containing new. If the old argument points to the pathname of a directory, write access permission may be required for the directory named by old, and, if it exists, the directory named by new.
If the link named by the new argument exists and the file's link count becomes zero when it is removed and no process has the file open, the space occupied by the file is freed and the file is no longer accessible. If one of more processes have the file open when the last link is removed, the link is removed before rename returns, but the removal of the file contents is postponed until all references to the file have been closed.
Upon successful completion, the
rename
function marks for update the
st_ctime
and
st_mtime
fields of the parent directory of each file.
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1)
;
and
NIST FIPS 151-1
.