|
Packit |
7cfc04 |
'\" et
|
|
Packit |
7cfc04 |
.TH RENAME "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
|
|
Packit |
7cfc04 |
.SH PROLOG
|
|
Packit |
7cfc04 |
This manual page is part of the POSIX Programmer's Manual.
|
|
Packit |
7cfc04 |
The Linux implementation of this interface may differ (consult
|
|
Packit |
7cfc04 |
the corresponding Linux manual page for details of Linux behavior),
|
|
Packit |
7cfc04 |
or the interface may not be implemented on Linux.
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
.SH NAME
|
|
Packit |
7cfc04 |
rename, renameat
|
|
Packit |
7cfc04 |
\(em rename file relative to directory file descriptor
|
|
Packit |
7cfc04 |
.SH SYNOPSIS
|
|
Packit |
7cfc04 |
.LP
|
|
Packit |
7cfc04 |
.nf
|
|
Packit |
7cfc04 |
#include <stdio.h>
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
int rename(const char *\fIold\fP, const char *\fInew\fP);
|
|
Packit |
7cfc04 |
int renameat(int \fIoldfd\fP, const char *\fIold\fP, int \fInewfd\fP,
|
|
Packit |
7cfc04 |
const char *\fInew\fP);
|
|
Packit |
7cfc04 |
.fi
|
|
Packit |
7cfc04 |
.SH DESCRIPTION
|
|
Packit |
7cfc04 |
For
|
|
Packit |
7cfc04 |
\fIrename\fR():
|
|
Packit |
7cfc04 |
The functionality described on this reference page is aligned with the
|
|
Packit |
7cfc04 |
ISO\ C standard. Any conflict between the requirements described here and the
|
|
Packit |
7cfc04 |
ISO\ C standard is unintentional. This volume of POSIX.1\(hy2008 defers to the ISO\ C standard.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIrename\fR()
|
|
Packit |
7cfc04 |
function shall change the name of a file. The
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
argument points to the pathname of the file to be renamed. The
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument points to the new pathname of the file.
|
|
Packit |
7cfc04 |
If the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument does not resolve to an existing directory entry for a file of
|
|
Packit |
7cfc04 |
type directory and the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument contains at least one non-\c
|
|
Packit |
7cfc04 |
<slash>
|
|
Packit |
7cfc04 |
character and ends with one or more trailing
|
|
Packit |
7cfc04 |
<slash>
|
|
Packit |
7cfc04 |
characters after all symbolic links have been processed,
|
|
Packit |
7cfc04 |
\fIrename\fR()
|
|
Packit |
7cfc04 |
shall fail.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If either the
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument names a symbolic link,
|
|
Packit |
7cfc04 |
\fIrename\fR()
|
|
Packit |
7cfc04 |
shall operate on the symbolic link itself, and shall not resolve the
|
|
Packit |
7cfc04 |
last component of the argument. If the
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
argument and the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument resolve to either the same existing directory entry or different
|
|
Packit |
7cfc04 |
directory entries for the same existing file,
|
|
Packit |
7cfc04 |
\fIrename\fR()
|
|
Packit |
7cfc04 |
shall return successfully and perform no other action.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If the
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
argument points to the pathname of a file that is not a directory, the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument shall not point to the pathname of a directory. If the link
|
|
Packit |
7cfc04 |
named by the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument exists, it shall be removed and
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
renamed to
|
|
Packit |
7cfc04 |
.IR new .
|
|
Packit |
7cfc04 |
In this case, a link named
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
shall remain visible to other processes throughout the renaming operation
|
|
Packit |
7cfc04 |
and refer either to the file referred to by
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
before the operation began. Write access permission is required for
|
|
Packit |
7cfc04 |
both the directory containing
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
and the directory containing
|
|
Packit |
7cfc04 |
.IR new .
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If the
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
argument points to the pathname of a directory, the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument shall not point to the pathname of a file that is not a
|
|
Packit |
7cfc04 |
directory. If the directory named by the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument exists, it shall be removed and
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
renamed to
|
|
Packit |
7cfc04 |
.IR new .
|
|
Packit |
7cfc04 |
In this case, a link named
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
shall exist throughout the renaming operation and shall refer either to
|
|
Packit |
7cfc04 |
the directory referred to by
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
before the operation began. If
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
names an existing directory, it shall be required to be an empty
|
|
Packit |
7cfc04 |
directory.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If either
|
|
Packit |
7cfc04 |
.IR pathname
|
|
Packit |
7cfc04 |
argument refers to a path whose final component is either dot or
|
|
Packit |
7cfc04 |
dot-dot,
|
|
Packit |
7cfc04 |
\fIrename\fR()
|
|
Packit |
7cfc04 |
shall fail.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If the
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
argument points to a pathname of a symbolic link, the symbolic link
|
|
Packit |
7cfc04 |
shall be renamed. If the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument points to a pathname of a symbolic link, the symbolic link
|
|
Packit |
7cfc04 |
shall be removed.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
pathname shall not name an ancestor directory of the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
pathname. Write access permission is required for the directory containing
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
and the directory containing
|
|
Packit |
7cfc04 |
.IR new .
|
|
Packit |
7cfc04 |
If the
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
argument points to the pathname of a directory, write access permission
|
|
Packit |
7cfc04 |
may be required for the directory named by
|
|
Packit |
7cfc04 |
.IR old ,
|
|
Packit |
7cfc04 |
and, if it exists, the directory named by
|
|
Packit |
7cfc04 |
.IR new .
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If the link named by the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument exists and the file's link count becomes 0 when it is removed
|
|
Packit |
7cfc04 |
and no process has the file open, the space occupied by the file shall
|
|
Packit |
7cfc04 |
be freed and the file shall no longer be accessible. If one or more
|
|
Packit |
7cfc04 |
processes have the file open when the last link is removed, the link
|
|
Packit |
7cfc04 |
shall be removed before
|
|
Packit |
7cfc04 |
\fIrename\fR()
|
|
Packit |
7cfc04 |
returns, but the removal of the file contents shall be postponed until
|
|
Packit |
7cfc04 |
all references to the file are closed.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
Upon successful completion,
|
|
Packit |
7cfc04 |
\fIrename\fR()
|
|
Packit |
7cfc04 |
shall mark for update the last data modification and last file status
|
|
Packit |
7cfc04 |
change timestamps of the parent directory of each file.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If the
|
|
Packit |
7cfc04 |
\fIrename\fR()
|
|
Packit |
7cfc04 |
function fails for any reason other than
|
|
Packit |
7cfc04 |
.BR [EIO] ,
|
|
Packit |
7cfc04 |
any file named by
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
shall be unaffected.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIrenameat\fR()
|
|
Packit |
7cfc04 |
function shall be equivalent to the
|
|
Packit |
7cfc04 |
\fIrename\fR()
|
|
Packit |
7cfc04 |
function except in the case where either
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
specifies a relative path. If
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
is a relative path, the file to be renamed is located relative to the
|
|
Packit |
7cfc04 |
directory associated with the file descriptor
|
|
Packit |
7cfc04 |
.IR oldfd
|
|
Packit |
7cfc04 |
instead of the current working directory. If
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
is a relative path, the same happens only relative to the directory
|
|
Packit |
7cfc04 |
associated with
|
|
Packit |
7cfc04 |
.IR newfd .
|
|
Packit |
7cfc04 |
If the file descriptor was opened without O_SEARCH, the function
|
|
Packit |
7cfc04 |
shall check whether directory searches are permitted using the current
|
|
Packit |
7cfc04 |
permissions of the directory underlying the file descriptor. If the
|
|
Packit |
7cfc04 |
file descriptor was opened with O_SEARCH, the function shall not perform
|
|
Packit |
7cfc04 |
the check.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If
|
|
Packit |
7cfc04 |
\fIrenameat\fR()
|
|
Packit |
7cfc04 |
is passed the special value AT_FDCWD in the
|
|
Packit |
7cfc04 |
.IR oldfd
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR newfd
|
|
Packit |
7cfc04 |
parameter, the current working directory shall be used in the
|
|
Packit |
7cfc04 |
determination of the file for the respective
|
|
Packit |
7cfc04 |
.IR path
|
|
Packit |
7cfc04 |
parameter.
|
|
Packit |
7cfc04 |
.SH "RETURN VALUE"
|
|
Packit |
7cfc04 |
Upon successful completion, the
|
|
Packit |
7cfc04 |
\fIrename\fR()
|
|
Packit |
7cfc04 |
function shall return 0. Otherwise, it shall return \(mi1,
|
|
Packit |
7cfc04 |
.IR errno
|
|
Packit |
7cfc04 |
shall be set to indicate the error,
|
|
Packit |
7cfc04 |
and neither the file named by
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
nor the file named by
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
shall be changed or created.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
Upon successful completion, the
|
|
Packit |
7cfc04 |
\fIrenameat\fR()
|
|
Packit |
7cfc04 |
function shall return 0. Otherwise, it shall return \(mi1 and set
|
|
Packit |
7cfc04 |
.IR errno
|
|
Packit |
7cfc04 |
to indicate the error.
|
|
Packit |
7cfc04 |
.SH ERRORS
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIrename\fR()
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
\fIrenameat\fR()
|
|
Packit |
7cfc04 |
functions shall fail if:
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EACCES
|
|
Packit |
7cfc04 |
A component of either path prefix denies search permission; or one of
|
|
Packit |
7cfc04 |
the directories containing
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
denies write permissions; or, write permission is required and is
|
|
Packit |
7cfc04 |
denied for a directory pointed to by the
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
arguments.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EBUSY
|
|
Packit |
7cfc04 |
The directory named by
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
is currently in use by the system or another process, and the
|
|
Packit |
7cfc04 |
implementation considers this an error.
|
|
Packit |
7cfc04 |
.IP "[EEXIST]\ or\ [ENOTEMPTY]" 12
|
|
Packit |
7cfc04 |
.br
|
|
Packit |
7cfc04 |
The link named by
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
is a directory that is not an empty directory.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EINVAL
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
pathname names an ancestor directory of the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
pathname, or either pathname argument contains a final component that
|
|
Packit |
7cfc04 |
is dot or dot-dot.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EIO
|
|
Packit |
7cfc04 |
A physical I/O error has occurred.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EISDIR
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument points to a directory and the
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
argument points to a file that is not a directory.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ELOOP
|
|
Packit |
7cfc04 |
A loop exists in symbolic links encountered during resolution of the
|
|
Packit |
7cfc04 |
.IR path
|
|
Packit |
7cfc04 |
argument.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EMLINK
|
|
Packit |
7cfc04 |
The file named by
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
is a directory, and the link count of the parent directory of
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
would exceed
|
|
Packit |
7cfc04 |
{LINK_MAX}.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ENAMETOOLONG
|
|
Packit |
7cfc04 |
.br
|
|
Packit |
7cfc04 |
The length of a component of a pathname is longer than
|
|
Packit |
7cfc04 |
{NAME_MAX}.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ENOENT
|
|
Packit |
7cfc04 |
The link named by
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
does not name an existing file, a component of the path prefix of
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
does not exist, or either
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
points to an empty string.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ENOSPC
|
|
Packit |
7cfc04 |
The directory that would contain
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
cannot be extended.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ENOTDIR
|
|
Packit |
7cfc04 |
A component of either path prefix names an existing file that is
|
|
Packit |
7cfc04 |
neither a directory nor a symbolic link to a directory; or the
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
argument names a directory and the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument names a non-directory file; or the
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
argument contains at least one non-\c
|
|
Packit |
7cfc04 |
<slash>
|
|
Packit |
7cfc04 |
character and ends with one or more trailing
|
|
Packit |
7cfc04 |
<slash>
|
|
Packit |
7cfc04 |
characters and the last pathname component names an existing file that
|
|
Packit |
7cfc04 |
is neither a directory nor a symbolic link to a directory; or the
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
argument names an existing non-directory file and the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument names a nonexistent file, contains at least one non-\c
|
|
Packit |
7cfc04 |
<slash>
|
|
Packit |
7cfc04 |
character, and ends with one or more trailing
|
|
Packit |
7cfc04 |
<slash>
|
|
Packit |
7cfc04 |
characters; or the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument names an existing non-directory file, contains at least one non-\c
|
|
Packit |
7cfc04 |
<slash>
|
|
Packit |
7cfc04 |
character, and ends with one or more trailing
|
|
Packit |
7cfc04 |
<slash>
|
|
Packit |
7cfc04 |
characters.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EPERM " or " EACCES
|
|
Packit |
7cfc04 |
.br
|
|
Packit |
7cfc04 |
The S_ISVTX flag is set on the directory containing the file referred
|
|
Packit |
7cfc04 |
to by
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
and the process does not satisfy the criteria specified in the Base Definitions volume of POSIX.1\(hy2008,
|
|
Packit |
7cfc04 |
.IR "Section 4.2" ", " "Directory Protection"
|
|
Packit |
7cfc04 |
with respect to
|
|
Packit |
7cfc04 |
.IR old ;
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
refers to an existing file, the S_ISVTX flag is set on the directory
|
|
Packit |
7cfc04 |
containing this file, and the process does not satisfy the criteria
|
|
Packit |
7cfc04 |
specified in the Base Definitions volume of POSIX.1\(hy2008,
|
|
Packit |
7cfc04 |
.IR "Section 4.2" ", " "Directory Protection"
|
|
Packit |
7cfc04 |
with respect to this file.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EROFS
|
|
Packit |
7cfc04 |
The requested operation requires writing in a directory on a read-only
|
|
Packit |
7cfc04 |
file system.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EXDEV
|
|
Packit |
7cfc04 |
The links named by
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
are on different file systems and the implementation does not support
|
|
Packit |
7cfc04 |
links between file systems.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
In addition, the
|
|
Packit |
7cfc04 |
\fIrenameat\fR()
|
|
Packit |
7cfc04 |
function shall fail if:
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EACCES
|
|
Packit |
7cfc04 |
.IR oldfd
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR newfd
|
|
Packit |
7cfc04 |
was not opened with O_SEARCH and the permissions of the directory
|
|
Packit |
7cfc04 |
underlying
|
|
Packit |
7cfc04 |
.IR oldfd
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR newfd
|
|
Packit |
7cfc04 |
respectively do not permit directory searches.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EBADF
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
argument does not specify an absolute path and the
|
|
Packit |
7cfc04 |
.IR oldfd
|
|
Packit |
7cfc04 |
argument is neither AT_FDCWD nor a valid file descriptor open for
|
|
Packit |
7cfc04 |
reading or searching, or the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument does not specify an absolute path and the
|
|
Packit |
7cfc04 |
.IR newfd
|
|
Packit |
7cfc04 |
argument is neither AT_FDCWD nor a valid file descriptor open
|
|
Packit |
7cfc04 |
for reading or searching.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ENOTDIR
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
argument is not an absolute path and
|
|
Packit |
7cfc04 |
.IR oldfd
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR newfd ,
|
|
Packit |
7cfc04 |
respectively, is a file descriptor associated with a non-directory file.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIrename\fR()
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
\fIrenameat\fR()
|
|
Packit |
7cfc04 |
functions may fail if:
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EBUSY
|
|
Packit |
7cfc04 |
The file named by the
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
arguments is a named STREAM.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ELOOP
|
|
Packit |
7cfc04 |
More than
|
|
Packit |
7cfc04 |
{SYMLOOP_MAX}
|
|
Packit |
7cfc04 |
symbolic links were encountered during resolution of the
|
|
Packit |
7cfc04 |
.IR path
|
|
Packit |
7cfc04 |
argument.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ENAMETOOLONG
|
|
Packit |
7cfc04 |
.br
|
|
Packit |
7cfc04 |
The length of a pathname exceeds
|
|
Packit |
7cfc04 |
{PATH_MAX},
|
|
Packit |
7cfc04 |
or pathname resolution of a symbolic link produced an intermediate
|
|
Packit |
7cfc04 |
result with a length that exceeds
|
|
Packit |
7cfc04 |
{PATH_MAX}.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ETXTBSY
|
|
Packit |
7cfc04 |
The file named by
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
exists and is the last directory entry to a pure procedure (shared text)
|
|
Packit |
7cfc04 |
file that is being executed.
|
|
Packit |
7cfc04 |
.LP
|
|
Packit |
7cfc04 |
.IR "The following sections are informative."
|
|
Packit |
7cfc04 |
.SH EXAMPLES
|
|
Packit |
7cfc04 |
.SS "Renaming a File"
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The following example shows how to rename a file named
|
|
Packit |
7cfc04 |
.BR /home/cnd/mod1
|
|
Packit |
7cfc04 |
to
|
|
Packit |
7cfc04 |
.BR /home/cnd/mod2 .
|
|
Packit |
7cfc04 |
.sp
|
|
Packit |
7cfc04 |
.RS 4
|
|
Packit |
7cfc04 |
.nf
|
|
Packit |
7cfc04 |
\fB
|
|
Packit |
7cfc04 |
#include <stdio.h>
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
int status;
|
|
Packit |
7cfc04 |
\&...
|
|
Packit |
7cfc04 |
status = rename("/home/cnd/mod1", "/home/cnd/mod2");
|
|
Packit |
7cfc04 |
.fi \fR
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
.RE
|
|
Packit |
7cfc04 |
.SH "APPLICATION USAGE"
|
|
Packit |
7cfc04 |
Some implementations mark for update the last file status change timestamp
|
|
Packit |
7cfc04 |
of renamed files and some do not. Applications which make use of the
|
|
Packit |
7cfc04 |
last file status change timestamp may behave differently with respect
|
|
Packit |
7cfc04 |
to renamed files unless they are designed to allow for either behavior.
|
|
Packit |
7cfc04 |
.SH RATIONALE
|
|
Packit |
7cfc04 |
This
|
|
Packit |
7cfc04 |
\fIrename\fR()
|
|
Packit |
7cfc04 |
function is equivalent for regular files to that defined by the ISO\ C standard.
|
|
Packit |
7cfc04 |
Its inclusion here expands that definition to include actions on
|
|
Packit |
7cfc04 |
directories and specifies behavior when the
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
parameter names a file that already exists. That specification
|
|
Packit |
7cfc04 |
requires that the action of the function be atomic.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
One of the reasons for introducing this function was to have a means of
|
|
Packit |
7cfc04 |
renaming directories while permitting implementations to prohibit the
|
|
Packit |
7cfc04 |
use of
|
|
Packit |
7cfc04 |
\fIlink\fR()
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
\fIunlink\fR()
|
|
Packit |
7cfc04 |
with directories, thus constraining links to directories to those made by
|
|
Packit |
7cfc04 |
\fImkdir\fR().
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The specification that if
|
|
Packit |
7cfc04 |
.IR old
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.IR new
|
|
Packit |
7cfc04 |
refer to the same file is intended to guarantee that:
|
|
Packit |
7cfc04 |
.sp
|
|
Packit |
7cfc04 |
.RS 4
|
|
Packit |
7cfc04 |
.nf
|
|
Packit |
7cfc04 |
\fB
|
|
Packit |
7cfc04 |
rename("x", "x");
|
|
Packit |
7cfc04 |
.fi \fR
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
.RE
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
does not remove the file.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
Renaming dot or dot-dot is prohibited in order to prevent cyclical file
|
|
Packit |
7cfc04 |
system paths.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
See also the descriptions of
|
|
Packit |
7cfc04 |
.BR [ENOTEMPTY]
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR [ENAMETOOLONG]
|
|
Packit |
7cfc04 |
in
|
|
Packit |
7cfc04 |
\fIrmdir\fR()
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR [EBUSY]
|
|
Packit |
7cfc04 |
in
|
|
Packit |
7cfc04 |
\fIunlink\fR().
|
|
Packit |
7cfc04 |
For a discussion of
|
|
Packit |
7cfc04 |
.BR [EXDEV] ,
|
|
Packit |
7cfc04 |
see
|
|
Packit |
7cfc04 |
\fIlink\fR().
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The purpose of the
|
|
Packit |
7cfc04 |
\fIrenameat\fR()
|
|
Packit |
7cfc04 |
function is to rename files in directories other than the current
|
|
Packit |
7cfc04 |
working directory without exposure to race conditions. Any part of the
|
|
Packit |
7cfc04 |
path of a file could be changed in parallel to a call to
|
|
Packit |
7cfc04 |
\fIrename\fR(),
|
|
Packit |
7cfc04 |
resulting in unspecified behavior. By opening file descriptors for the
|
|
Packit |
7cfc04 |
source and target directories and using the
|
|
Packit |
7cfc04 |
\fIrenameat\fR()
|
|
Packit |
7cfc04 |
function it can be guaranteed that that renamed file is located correctly
|
|
Packit |
7cfc04 |
and the resulting file is in the desired directory.
|
|
Packit |
7cfc04 |
.SH "FUTURE DIRECTIONS"
|
|
Packit |
7cfc04 |
None.
|
|
Packit |
7cfc04 |
.SH "SEE ALSO"
|
|
Packit |
7cfc04 |
.IR "\fIlink\fR\^(\|)",
|
|
Packit |
7cfc04 |
.IR "\fIrmdir\fR\^(\|)",
|
|
Packit |
7cfc04 |
.IR "\fIsymlink\fR\^(\|)",
|
|
Packit |
7cfc04 |
.IR "\fIunlink\fR\^(\|)"
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The Base Definitions volume of POSIX.1\(hy2008,
|
|
Packit |
7cfc04 |
.IR "Section 4.2" ", " "Directory Protection",
|
|
Packit |
7cfc04 |
.IR "\fB<stdio.h>\fP"
|
|
Packit |
7cfc04 |
.SH COPYRIGHT
|
|
Packit |
7cfc04 |
Portions of this text are reprinted and reproduced in electronic form
|
|
Packit |
7cfc04 |
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
|
|
Packit |
7cfc04 |
-- Portable Operating System Interface (POSIX), The Open Group Base
|
|
Packit |
7cfc04 |
Specifications Issue 7, Copyright (C) 2013 by the Institute of
|
|
Packit |
7cfc04 |
Electrical and Electronics Engineers, Inc and The Open Group.
|
|
Packit |
7cfc04 |
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
|
|
Packit |
7cfc04 |
event of any discrepancy between this version and the original IEEE and
|
|
Packit |
7cfc04 |
The Open Group Standard, the original IEEE and The Open Group Standard
|
|
Packit |
7cfc04 |
is the referee document. The original Standard can be obtained online at
|
|
Packit |
7cfc04 |
http://www.unix.org/online.html .
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
Any typographical or formatting errors that appear
|
|
Packit |
7cfc04 |
in this page are most likely
|
|
Packit |
7cfc04 |
to have been introduced during the conversion of the source files to
|
|
Packit |
7cfc04 |
man page format. To report such errors, see
|
|
Packit |
7cfc04 |
https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|