rename.2: Document renameat2()

Some light edits to this patch by mtk.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Miklos Szeredi 2014-04-19 10:32:49 +02:00 committed by Michael Kerrisk
parent bf253d9b61
commit ab99efddee
1 changed files with 66 additions and 3 deletions

View File

@ -30,9 +30,9 @@
.\" Modified Thu Mar 3 09:49:35 2005 by Michael Haardt <michael@moria.de> .\" Modified Thu Mar 3 09:49:35 2005 by Michael Haardt <michael@moria.de>
.\" 2007-03-25, mtk, added various text to DESCRIPTION. .\" 2007-03-25, mtk, added various text to DESCRIPTION.
.\" .\"
.TH RENAME 2 2014-02-21 "Linux" "Linux Programmer's Manual" .TH RENAME 2 2014-04-19 "Linux" "Linux Programmer's Manual"
.SH NAME .SH NAME
rename, renameat \- change the name or location of a file rename, renameat, renameat2 \- change the name or location of a file
.SH SYNOPSIS .SH SYNOPSIS
.nf .nf
.B #include <stdio.h> .B #include <stdio.h>
@ -44,6 +44,9 @@ rename, renameat \- change the name or location of a file
.sp .sp
.BI "int renameat(int " olddirfd ", const char *" oldpath , .BI "int renameat(int " olddirfd ", const char *" oldpath ,
.BI " int " newdirfd ", const char *" newpath ); .BI " int " newdirfd ", const char *" newpath );
.BI "int renameat2(int " olddirfd ", const char *" oldpath ,
.BI " int " newdirfd ", const char *" newpath ", unsigned int " flags );
.fi .fi
.sp .sp
.in -4n .in -4n
@ -61,6 +64,7 @@ _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
.TP .TP
Before glibc 2.10: Before glibc 2.10:
_ATFILE_SOURCE _ATFILE_SOURCE
.\" FIXME need to define FTMs for renameat2(), once it hits glibc
.RE .RE
.ad .ad
.PD .PD
@ -163,6 +167,38 @@ See
.BR openat (2) .BR openat (2)
for an explanation of the need for for an explanation of the need for
.BR renameat (). .BR renameat ().
.SS renameat2()
.BR renameat2 ()
has an additional
.I flags
argument.
A
.BR renameat2 ()
call with a zero
.I flags
argument is equivalent to
.BR renameat ().
The
.I flags
argument is a bit mask consisting of zero or more of the following flags:
.TP
.B RENAME_NOREPLACE
Don't overwrite
.IR newpath .
of the rename.
Return an error if
.IR newpath
already exists.
.TP
.B RENAME_EXCHANGE
Atomically exchange
.IR oldpath
and
.IR newpath .
Both pathnames must exist
but may be of different types (e.g., one could be a non-empty directory
and the other a symbolic link).
.SH RETURN VALUE .SH RETURN VALUE
On success, zero is returned. On success, zero is returned.
On error, \-1 is returned, and On error, \-1 is returned, and
@ -306,7 +342,9 @@ does not work across different mount points,
even if the same filesystem is mounted on both.) even if the same filesystem is mounted on both.)
.PP .PP
The following additional errors can occur for The following additional errors can occur for
.BR renameat (): .BR renameat ()
and
.BR renameat2 ():
.TP .TP
.B EBADF .B EBADF
.I olddirfd .I olddirfd
@ -323,6 +361,31 @@ or similar for
.I newpath .I newpath
and and
.I newdirfd .I newdirfd
.PP
The following additional errors can occur for
.BR renameat2 ():
.TP
.B EEXIST
.I flags
contains
.B RENAME_NOREPLACE
and
.I newpath
already exists.
.TP
.B EINVAL
Invalid combination of
.IR flags .
.TP
.B EINVAL
The filesystem does not support one of the flags in
.IR flags .
.TP
.B ENOENT
.I flags
contain
.B RENAME_EXCHANGE
and the target of the rename does not exist.
.SH VERSIONS .SH VERSIONS
.BR renameat () .BR renameat ()
was added to Linux in kernel 2.6.16; was added to Linux in kernel 2.6.16;