]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/rename.2
Format errno.
[thirdparty/man-pages.git] / man2 / rename.2
CommitLineData
fea681da
MK
1.\" Hey Emacs! This file is -*- nroff -*- source.
2.\"
3.\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4.\" 1993 Michael Haardt;
5.\" 1993,1995 Ian Jackson.
6.\"
7.\" Permission is granted to make and distribute verbatim copies of this
8.\" manual provided the copyright notice and this permission notice are
9.\" preserved on all copies.
10.\"
11.\" Permission is granted to copy and distribute modified versions of this
12.\" manual under the conditions for verbatim copying, provided that the
13.\" entire resulting derived work is distributed under the terms of a
14.\" permission notice identical to this one.
c13182ef 15.\"
fea681da
MK
16.\" Since the Linux kernel and libraries are constantly changing, this
17.\" manual page may be incorrect or out-of-date. The author(s) assume no
18.\" responsibility for errors or omissions, or for damages resulting from
19.\" the use of the information contained herein. The author(s) may not
20.\" have taken the same level of care in the production of this manual,
21.\" which is licensed free of charge, as they might when working
22.\" professionally.
c13182ef 23.\"
fea681da
MK
24.\" Formatted or processed versions of this manual, if unaccompanied by
25.\" the source, must acknowledge the copyright and authors of this work.
26.\"
27.\" Modified Sat Jul 24 00:35:52 1993 by Rik Faith <faith@cs.unc.edu>
28.\" Modified Thu Jun 4 12:21:13 1998 by Andries Brouwer <aeb@cwi.nl>
2d5d4b0d 29.\" Modified Thu Mar 3 09:49:35 2005 by Michael Haardt <michael@moria.de>
f6a4055f 30.\" 2007-03-25, mtk, added various text to DESCRIPTION.
fea681da 31.\"
d9343c5c 32.TH RENAME 2 1998-06-04 "Linux" "Linux Programmer's Manual"
fea681da
MK
33.SH NAME
34rename \- change the name or location of a file
35.SH SYNOPSIS
36.B #include <stdio.h>
37.sp
38.BI "int rename(const char *" oldpath ", const char *" newpath );
39.SH DESCRIPTION
e511ffb6 40.BR rename ()
fea681da 41renames a file, moving it between directories if required.
fea681da
MK
42Any other hard links to the file (as created using
43.BR link (2))
44are unaffected.
f6a4055f
MK
45Open file descriptors for
46.I oldpath
47are also unaffected.
fea681da
MK
48
49If
50.I newpath
51already exists it will be atomically replaced (subject to
e9496f74 52a few conditions; see ERRORS below), so that there is
fea681da
MK
53no point at which another process attempting to access
54.I newpath
55will find it missing.
56
f6a4055f
MK
57If
58.I oldpath
59and
60.I newpath
61are existing hard links referring to the same file, then
62.BR rename ()
63does nothing, and returns a success status.
64
fea681da
MK
65If
66.I newpath
67exists but the operation fails for some reason
e511ffb6 68.BR rename ()
fea681da
MK
69guarantees to leave an instance of
70.I newpath
71in place.
72
f6a4055f
MK
73.I oldpath
74can specify a directory.
c13182ef 75In this case,
f6a4055f
MK
76.I newpath
77must either not exist, or it must specify an empty directory.
78
fea681da
MK
79However, when overwriting there will probably be a window in which
80both
81.I oldpath
82and
83.I newpath
84refer to the file being renamed.
85
86If
87.I oldpath
88refers to a symbolic link the link is renamed; if
89.I newpath
90refers to a symbolic link the link will be overwritten.
91.SH "RETURN VALUE"
c13182ef
MK
92On success, zero is returned.
93On error, \-1 is returned, and
fea681da
MK
94.I errno
95is set appropriately.
96.SH ERRORS
97.TP
98.B EACCES
99Write permission is denied for the directory containing
100.I oldpath
101or
102.IR newpath ,
103or, search permission is denied for one of the directories
104in the path prefix of
105.I oldpath
106or
107.IR newpath ,
108or
109.I oldpath
110is a directory and does not allow write permission (needed to update
111the
836f07c1 112.I ..
fea681da
MK
113entry).
114(See also
ad7cc990 115.BR path_resolution (7).)
fea681da
MK
116.TP
117.B EBUSY
118The rename fails because
119.IR oldpath " or " newpath
120is a directory that is in use by some process (perhaps as
121current working directory, or as root directory, or because
122it was open for reading) or is in use by the system
123(for example as mount point), while the system considers
124this an error.
125(Note that there is no requirement to return EBUSY in such
e9496f74 126cases \(em there is nothing wrong with doing the rename anyway \(em
fea681da
MK
127but it is allowed to return EBUSY if the system cannot otherwise
128handle such situations.)
129.TP
130.B EFAULT
131.IR oldpath " or " newpath " points outside your accessible address space."
132.TP
133.B EINVAL
134The new pathname contained a path prefix of the old, or, more generally,
135an attempt was made to make a directory a subdirectory of itself.
136.TP
137.B EISDIR
138.I newpath
139is an existing directory, but
140.I oldpath
141is not a directory.
142.TP
143.B ELOOP
144Too many symbolic links were encountered in resolving
145.IR oldpath " or " newpath .
146.TP
147.B EMLINK
148.I oldpath
149already has the maximum number of links to it, or
150it was a directory and the directory containing
151.I newpath
152has the maximum number of links.
153.TP
154.B ENAMETOOLONG
155.IR oldpath " or " newpath " was too long."
156.TP
157.B ENOENT
158A directory component in
159.I oldpath " or " newpath
160does not exist or is a dangling symbolic link.
161.TP
162.B ENOMEM
163Insufficient kernel memory was available.
164.TP
165.B ENOSPC
166The device containing the file has no room for the new directory
167entry.
168.TP
169.B ENOTDIR
170A component used as a directory in
171.IR oldpath " or " newpath
172is not, in fact, a directory.
173Or,
174.I oldpath
175is a directory, and
176.I newpath
177exists but is not a directory.
178.TP
179.BR ENOTEMPTY " or " EEXIST
180.IR newpath
75b94dc3 181is a non-empty directory, that is, contains entries other than "." and "..".
fea681da
MK
182.TP
183.BR EPERM " or " EACCES
184The directory containing
185.I oldpath
186has the sticky bit
187.RB ( S_ISVTX )
188set and the process's effective user ID is neither
189the user ID of the file to be deleted nor that of the directory
190containing it, and the process is not privileged
191(Linux: does not have the
192.B CAP_FOWNER
193capability);
194or
195.I newpath
196is an existing file and the directory containing it has the sticky bit set
197and the process's effective user ID is neither the user ID of the file
198to be replaced nor that of the directory containing it,
199and the process is not privileged
200(Linux: does not have the
201.B CAP_FOWNER
202capability);
203or the filesystem containing
204.IR pathname
205does not support renaming of the type requested.
206.TP
207.B EROFS
208The file is on a read-only filesystem.
209.TP
210.B EXDEV
211.IR oldpath " and " newpath
2d5d4b0d
MK
212are not on the same mounted filesystem.
213(Linux permits a filesystem to be mounted at multiple points, but
214.BR rename (2)
215does not work across different mount points,
216even if the same filesystem is mounted on both.)
fea681da 217.SH "CONFORMING TO"
1eb85d14 2184.3BSD, C89, C99, POSIX.1-2001.
fea681da
MK
219.SH BUGS
220On NFS filesystems, you can not assume that if the operation
c13182ef
MK
221failed the file was not renamed.
222If the server does the rename operation
fea681da 223and then crashes, the retransmitted RPC which will be processed when the
c13182ef
MK
224server is up again causes a failure.
225The application is expected to
226deal with this.
227See
fea681da
MK
228.BR link (2)
229for a similar problem.
230.SH "SEE ALSO"
231.BR mv (1),
232.BR chmod (2),
233.BR link (2),
f5958902 234.BR renameat (2),
fea681da 235.BR symlink (2),
ad7cc990
MK
236.BR unlink (2),
237.BR path_resolution (7)