RENAME(2) RENAME(2)
NAME
rename - change the name of a file
SYNOPSIS
int rename(old, new)
char *from, *to;
DESCRIPTION
rename changes the name of a file from old to new. If old
is a file (not a directory), new cannot be a directory, and
if new is an existing file, it will be removed and old
renamed. If old is a directory, and new exists, new must be
empty, in which case it will be removed and old renamed. If
old and new refer to the same file, rename will return
successfully without making any changes.
RETURN VALUE
A 0 value is returned if the operation succeeds, otherwise
rename returns -1 and the global variable errno indicates
the reason for the failure.
ERRORS
rename will fail and neither of the files named as arguments
will be affected if any of the following are true:
[ENOTDIR] A component of either path prefix is not a
directory, or old names a directory, and new is
not a directory.
[ENAMETOOLONG]
A component of a pathname exceeded NAME_MAX
characters while _POSIX_NO_TRUE is in effect,
or an entire pathname exceeded PATH_MAX.
[ENOENT] The link named by old does not exist or either
old or new points to an empty string.
[EACCES] A component of either path prefix denies search
permission, or one of the directories
containing old or new denies write permission,
Page 1 May 1989
RENAME(2) RENAME(2)
or the requested link requires writing in a
directory with a mode that denies write
permission.
[EXDEV] The link named by to and the file named by from
are on different logical devices (file
systems).
[EROFS] The requested link requires writing in a
directory on a read-only file system.
[EINVAL] The new pathname contains a path prefix that
names old.
[EBUSY] The directory named by old or new cannot be
renamed because it is being used by the system
or another process.
[ENOTEMPTY] The directory named by new contains files other
than "." or "..".
[EISDIR] The new points to a directory, and old is not a
directory.
[ENOSPC] The directory that would enter new cannot be
extended.
SEE ALSO
mv(1), link(2), open(2), symlink(2), unlink(2).
Page 2 May 1989