[0m


RENAME(2)	    UNIX Programmer's Manual		RENAME(2)



[1mNAME
     [0mrename - change the name of a file

[1mSYNOPSIS
     rename(from, to)
     char *from, *to;

DESCRIPTION
     [0m_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.

[1mCAVEAT
     [0mThe 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.

[1mRETURN VALUE
     [0mA 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.

[1mERRORS
     [0m_R_e_n_a_m_e will fail and neither of the argument files will be
     affected if any of the following are true:

     [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 _t_o does not exist.

     [EACCES]	    A component of either path prefix denies
		    search permission.




Printed 14/10/93    Revision 1.3 of 22/10/90			1






RENAME(2)	    UNIX Programmer's Manual		RENAME(2)



     [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]	    _F_r_o_m or _t_o points outside the process's allo-
		    cated address space.

     [EINVAL]	    _F_r_o_m is a parent directory of _t_o, or an



Printed 14/10/93    Revision 1.3 of 22/10/90			2






RENAME(2)	    UNIX Programmer's Manual		RENAME(2)



		    attempt is made to rename ``.'' or ``..''.

     [ENOTEMPTY]    _T_o is a directory and is not empty.

[1mSEE ALSO
     [0mopen(2)

















































Printed 14/10/93    Revision 1.3 of 22/10/90			3



[0m