]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/rename.2
xnu-344.tar.gz
[apple/xnu.git] / bsd / man / man2 / rename.2
CommitLineData
9bccf70c
A
1.\" $NetBSD: rename.2,v 1.7 1995/02/27 12:36:15 cgd Exp $
2.\"
3.\" Copyright (c) 1983, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\" @(#)rename.2 8.1 (Berkeley) 6/4/93
35.\"
36.Dd June 4, 1993
37.Dt RENAME 2
38.Os BSD 4.2
39.Sh NAME
40.Nm rename
41.Nd change the name of a file
42.Sh SYNOPSIS
43.Fd #include <stdio.h>
44.Ft int
45.Fn rename "const char *from" "const char *to"
46.Sh DESCRIPTION
47.Fn Rename
48causes the link named
49.Fa from
50to be renamed as
51.Fa to .
52If
53.Fa to
54exists, it is first removed.
55Both
56.Fa from
57and
58.Fa to
59must be of the same type (that is, both directories or both
60non-directories), and must reside on the same file system.
61.Pp
62.Fn Rename
63guarantees that an instance of
64.Fa to
65will always exist, even if the system should crash in
66the middle of the operation.
67.Pp
68If the final component of
69.Fa from
70is a symbolic link,
71the symbolic link is renamed,
72not the file or directory to which it points.
73.Sh CAVEAT
74The system can deadlock if a loop in the file system graph is present.
75This loop takes the form of an entry in directory
76.Ql Pa a ,
77say
78.Ql Pa a/foo ,
79being a hard link to directory
80.Ql Pa b ,
81and an entry in
82directory
83.Ql Pa b ,
84say
85.Ql Pa b/bar ,
86being a hard link
87to directory
88.Ql Pa a .
89When such a loop exists and two separate processes attempt to
90perform
91.Ql rename a/foo b/bar
92and
93.Ql rename b/bar a/foo ,
94respectively,
95the system may deadlock attempting to lock
96both directories for modification.
97Hard links to directories should be
98replaced by symbolic links by the system administrator.
99.Sh RETURN VALUES
100A 0 value is returned if the operation succeeds, otherwise
101.Fn rename
102returns -1 and the global variable
103.Va errno
104indicates the reason for the failure.
105.Sh ERRORS
106.Fn Rename
107will fail and neither of the argument files will be
108affected if:
109.Bl -tag -width Er
110.It Bq Er ENAMETOOLONG
111A component of a pathname exceeded
112.Dv {NAME_MAX}
113characters, or an entire path name exceeded
114.Dv {PATH_MAX}
115characters.
116.It Bq Er ENOENT
117A component of the
118.Fa from
119path does not exist,
120or a path prefix of
121.Fa to
122does not exist.
123.It Bq Er EACCES
124A component of either path prefix denies search permission.
125.It Bq Er EACCES
126The requested link requires writing in a directory with a mode
127that denies write permission.
128.It Bq Er EPERM
129The directory containing
130.Fa from
131is marked sticky,
132and neither the containing directory nor
133.Fa from
134are owned by the effective user ID.
135.It Bq Er EPERM
136The
137.Fa to
138file exists,
139the directory containing
140.Fa to
141is marked sticky,
142and neither the containing directory nor
143.Fa to
144are owned by the effective user ID.
145.It Bq Er ELOOP
146Too many symbolic links were encountered in translating either pathname.
147.It Bq Er ENOTDIR
148A component of either path prefix is not a directory.
149.It Bq Er ENOTDIR
150.Fa from
151is a directory, but
152.Fa to
153is not a directory.
154.It Bq Er EISDIR
155.Fa to
156is a directory, but
157.Fa from
158is not a directory.
159.It Bq Er EXDEV
160The link named by
161.Fa to
162and the file named by
163.Fa from
164are on different logical devices (file systems). Note that this error
165code will not be returned if the implementation permits cross-device
166links.
167.It Bq Er ENOSPC
168The directory in which the entry for the new name is being placed
169cannot be extended because there is no space left on the file
170system containing the directory.
171.It Bq Er EDQUOT
172The directory in which the entry for the new name
173is being placed cannot be extended because the
174user's quota of disk blocks on the file system
175containing the directory has been exhausted.
176.It Bq Er EIO
177An I/O error occurred while making or updating a directory entry.
178.It Bq Er EROFS
179The requested link requires writing in a directory on a read-only file
180system.
181.It Bq Er EFAULT
182.Em Path
183points outside the process's allocated address space.
184.It Bq Er EINVAL
185.Fa From
186is a parent directory of
187.Fa to ,
188or an attempt is made to rename
189.Ql \&.
190or
191.Ql \&.. .
192.It Bq Er ENOTEMPTY
193.Fa To
194is a directory and is not empty.
195.El
196.Sh SEE ALSO
197.Xr open 2
198.Xr symlink 7
199.Sh STANDARDS
200The
201.Fn rename
202function conforms to
203.St -p1003.1-88 .