|RENAME(2)||System Calls Manual||RENAME(2)|
— change the name of a file
char *from, const char
fromfd, const char
*from, int tofd,
const char *to);
function causes the link named from to be renamed as
to. If to exists, it is first
removed. Both from and to must
be of the same type (that is, both directories or both non-directories), and
must reside on the same file system.
guarantees that if to already exists, an instance of
to will always exist, even if the system should crash
in the middle of the operation.
If the final component of from is a symbolic link, the symbolic link is renamed, not the file or directory to which it points.
function is equivalent to
rename() except that where
from or to specifies a relative
path, the directory entry names used are resolved relative to the
directories associated with file descriptors fromfd or
tofd (respectively) instead of the current working
Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.
renameat() will fail and neither of the argument
files will be affected if:
NAME_MAXcharacters, or an entire pathname (including the terminating NUL) exceeded
.’ or ‘
renameat() will fail if:
AT_FDCWDnor a valid file descriptor.
renameat() functions conform to
IEEE Std 1003.1-2008 (“POSIX.1”).
renameat() function appeared in
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/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.
|September 10, 2015||OpenBSD-7.0|