new copyright notice
[unix-history] / usr / src / lib / libc / sys / rename.2
CommitLineData
88b3ccf2
KB
1.\" Copyright (c) 1983 The Regents of the University of California.
2.\" All rights reserved.
786fe04f 3.\"
91cff1e1 4.\" %sccs.include.redist.man%
88b3ccf2 5.\"
91cff1e1 6.\" @(#)rename.2 6.6 (Berkeley) %G%
786fe04f 7.\"
0e4a927e 8.TH RENAME 2 ""
786fe04f
KM
9.UC 5
10.SH NAME
11rename \- change the name of a file
12.SH SYNOPSIS
13.ft B
14.nf
15rename(from, to)
16char *from, *to;
17.fi
18.ft R
19.SH DESCRIPTION
20.I Rename
21causes the link named
22.I from
23to be renamed as
24.IR to .
25If
26.I to
27exists, then it is first removed.
28Both
29.I from
30and
31.I to
32must be of the same type (that is, both directories or both
33non-directories), and must reside on the same file system.
34.PP
35.I Rename
36guarantees that an instance of
37.I to
38will always exist, even if the system should crash in
39the middle of the operation.
dbe80be1
KM
40.PP
41If the final component of
42.I from
43is a symbolic link,
44the symbolic link is renamed,
45not the file or directory to which it points.
786fe04f
KM
46.SH CAVEAT
47The system can deadlock if a loop in the file system graph is present.
48This loop takes the form of an entry in directory \*(lqa\*(rq,
49say \*(lqa/foo\*(rq,
50being a hard link to directory \*(lqb\*(rq, and an entry in
51directory \*(lqb\*(rq, say \*(lqb/bar\*(rq, being a hard link
52to directory \*(lqa\*(rq.
53When such a loop exists and two separate processes attempt to
54perform \*(lqrename a/foo b/bar\*(rq and \*(lqrename b/bar a/foo\*(rq,
55respectively,
56the system may deadlock attempting to lock
57both directories for modification.
58Hard links to directories should be
59replaced by symbolic links by the system administrator.
60.SH "RETURN VALUE"
61A 0 value is returned if the operation succeeds, otherwise
62.I rename
63returns \-1 and the global variable
64.I errno
65indicates the reason for the failure.
66.SH "ERRORS
67.I Rename
68will fail and neither of the argument files will be
69affected if any of the following are true:
70.TP 15
b5984ffe
KM
71[EINVAL]
72Either pathname contains a character with the high-order bit set.
73.TP 15
74[ENAMETOOLONG]
75A component of either pathname exceeded 255 characters,
76or the entire length of either path name exceeded 1023 characters.
786fe04f
KM
77.TP 15
78[ENOENT]
b5984ffe
KM
79A component of the \fIfrom\fP path does not exist,
80or a path prefix of \fIto\fP does not exist.
786fe04f
KM
81.TP 15
82[EACCES]
83A component of either path prefix denies search permission.
84.TP 15
b5984ffe
KM
85[EACCES]
86The requested link requires writing in a directory with a mode
87that denies write permission.
88.TP 15
fd690c8b
KM
89[EPERM]
90The directory containing \fIfrom\fP is marked sticky,
91and neither the containing directory nor \fIfrom\fP
92are owned by the effective user ID.
93.TP 15
94[EPERM]
95The \fIto\fP file exists,
96the directory containing \fIto\fP is marked sticky,
97and neither the containing directory nor \fIto\fP
98are owned by the effective user ID.
99.TP 15
b5984ffe
KM
100[ELOOP]
101Too many symbolic links were encountered in translating either pathname.
102.TP 15
103[ENOTDIR]
104A component of either path prefix is not a directory.
105.TP 15
106[ENOTDIR]
107.I From
108is a directory, but \fIto\fP is not a directory.
786fe04f 109.TP 15
b5984ffe
KM
110[EISDIR]
111.I To
112is a directory, but \fIfrom\fP is not a directory.
786fe04f
KM
113.TP 15
114[EXDEV]
115The link named by \fIto\fP and the file named by \fIfrom\fP
116are on different logical devices (file systems). Note that this error
117code will not be returned if the implementation permits cross-device
118links.
119.TP 15
fd690c8b
KM
120[ENOSPC]
121The directory in which the entry for the new name is being placed
122cannot be extended because there is no space left on the file
123system containing the directory.
124.TP 15
125[EDQUOT]
126The directory in which the entry for the new name
127is being placed cannot be extended because the
128user's quota of disk blocks on the file system
129containing the directory has been exhausted.
130.TP 15
b5984ffe
KM
131[EIO]
132An I/O error occurred while making or updating a directory entry.
786fe04f
KM
133.TP 15
134[EROFS]
135The requested link requires writing in a directory on a read-only file
136system.
137.TP 15
138[EFAULT]
139.I Path
140points outside the process's allocated address space.
141.TP 15
142[EINVAL]
143.I From
144is a parent directory of
b5984ffe
KM
145.IR to ,
146or an attempt is made to rename ``.'' or ``..''.
147.TP 15
148[ENOTEMPTY]
149.I To
150is a directory and is not empty.
786fe04f
KM
151.SH "SEE ALSO"
152open(2)