2.11BSD/man/cat2/rename.0
RENAME(2) UNIX Programmer's Manual 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 opera-
tion.
If the final component of _f_r_o_m is a symbolic link, the sym-
bolic 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 direc-
tory "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 modifica-
tion. Hard links to directories should be replaced by sym-
bolic 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 FIto _d_o_e_s _n_o_t _e_x_i_s_t.
Printed 11/26/99 May 22, 1986 1
RENAME(2) UNIX Programmer's Manual RENAME(2)
[_E_A_C_C_E_S] A component of either path prefix denies
search permission.
[EACCES] The requested link requires writing in a
directory with a mode that denies write per-
mission.
[EPERM] The directory containing _f_r_o_m is marked
sticky, and neither 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 contain-
ing directory nor _t_o are owned by the effec-
tive 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 direc-
tory.
[EISDIR] _T_o is a directory, but _f_r_o_m is not a direc-
tory.
[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 implementation 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 directory has
been exhausted.
[EIO] An I/O error occurred while making or updat-
ing a directory 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
Printed 11/26/99 May 22, 1986 2
RENAME(2) UNIX Programmer's Manual RENAME(2)
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)
Printed 11/26/99 May 22, 1986 3