int rename(path1, path2) char *path1, *path2;
rename() renames the link named path1 as path2. If path2 exists, then it is first removed. If path2 refers to a directory, it must be an empty directory, and must not include path1 in its path prefix. Both path1 and path2 must be of the same type (that is, both directories or both non-directories), and must reside on the same file system. Write access permission is required for both the directory containing path1 and the directory containing path2. If a rename request relocates a directory in the hierarchy, write permission in the directory to be moved is needed, since its entry for the parent directory (..) must be updated.
rename() guarantees that an instance of path2 will always exist, even if the system should crash in the middle of the operation.
If the final component of path1 is a symbolic link, the symbolic link is renamed, not the file or directory to which it points.
If the file referred to by path2 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 or more processes have the file open when the last link is removed, the link is removed before rename() returns, but the file's contents are not removed until all references to the file have been closed.
Upon successful completion, rename() marks for update the st_ctime and st_mtime fields of the parent directory of each file.
rename() returns:
rename() will fail and neither path1 nor path2 will be affected if:
A component of the path prefix of either path1 or path2 denies search permission.
The requested rename requires writing in a directory with access permissions that deny write permission.
An attempt was made to rename `.' or `..'.
A pathname component is longer than {NAME_MAX} while {_POSIX_NO_TRUNC} is in effect (see pathconf.2v
The file named by path1 does not exist.
path1 names a directory and path2 names a nondirectory file.
In addition to the above, the following may also occur:
The system can deadlock if a loop in the file system graph is present. This loop takes the form of an entry in directory a, say a/file1, being a hard link to directory b, and an entry in directory b, say b/file2, being a hard link to directory a. When such a loop exists and two separate processes attempt to perform `rename a/file1 b/file2' and `rename b/file2 a/file1', respectively, the system may deadlock attempting to lock both directories for modification. Hard links to directories should not be used. System administrators should use symbolic links instead.
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97