RENAME(2) RENAME(2) NAME rename - change the name of a file SYNOPSIS rename(from, to) char *from, *to; DESCRIPTION _R_e_n_a_m_e causes the link named _f_r_o_m to be renamed as _t_o. If _t_o exists, then it is first removed. Both _f_r_o_m and _t_o must be of the same type (that is, both directories or both non-directories), and must reside on the same file system. _R_e_n_a_m_e guarantees that an instance of _t_o will always exist, even if the system should crash in the middle of the operation. If the final component of _f_r_o_m is a symbolic link, the symbolic link is renamed, not the file or directory to which it points. CAVEAT 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/foo”, being a hard link to directory “b”, and an entry in directory “b”, say “b/bar”, being a hard link to directory “a”. When such a loop exists and two separate processes attempt to perform “rename a/foo b/bar” and “rename b/bar a/foo”, respectively, the system may deadlock attempting to lock both directories for modification. Hard links to directories should be replaced by symbolic links by the system administrator. RETURN VALUE A 0 value is returned if the operation succeeds, otherwise _r_e_n_a_m_e returns -1 and the global variable _e_r_r_n_o indicates the reason for the failure. ERRORS _R_e_n_a_m_e will fail and neither of the argument files will be affected if any of the following are true: [EINVAL] Either pathname contains a character with the high-order bit set. [ENAMETOOLONG] A component of either pathname exceeded 255 characters, or the entire length of either path name exceeded 1023 characters. [ENOENT] A component of the _f_r_o_m path does not exist, or a path prefix of to _d_o_e_s _n_o_t _e_x_i_s_t_. _[_E_A_C_C_E_S_] A component of either path prefix denies search permis‐ sion. [EACCES] The requested link requires writing in a directory with a mode that denies write permission. [EPERM] The directory containing _f_r_o_m is marked sticky, and nei‐ ther the containing directory nor _f_r_o_m are owned by the effective user ID. [EPERM] The _t_o file exists, the directory containing _t_o is marked sticky, and neither the containing directory nor _t_o are owned by the effective user ID. [ELOOP] Too many symbolic links were encountered in translating either pathname. [ENOTDIR] A component of either path prefix is not a directory. [ENOTDIR] _F_r_o_m is a directory, but _t_o is not a directory. [EISDIR] _T_o is a directory, but _f_r_o_m is not a directory. [EXDEV] The link named by _t_o and the file named by _f_r_o_m are on different logical devices (file systems). Note that this error code will not be returned if the implementa‐ tion permits cross-device links. [ENOSPC] The directory in which the entry for the new name is being placed cannot be extended because there is no space left on the file system containing the directory. [EDQUOT] The directory in which the entry for the new name is being placed cannot be extended because the user’s quota of disk blocks on the file system containing the direc‐ tory has been exhausted. [EIO] An I/O error occurred while making or updating a direc‐ tory entry. [EROFS] The requested link requires writing in a directory on a read-only file system. [EFAULT] _P_a_t_h points outside the process’s allocated address space. [EINVAL] _F_r_o_m is a parent directory of _t_o, or an attempt is made to rename ‘‘.’’ or ‘‘..’’. [ENOTEMPTY] _T_o is a directory and is not empty. SEE ALSO open(2) 4.2 Berkeley Distribution May 22, 1986 RENAME(2)