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