Commit | Line | Data |
---|---|---|
786fe04f KM |
1 | .\" Copyright (c) 1983 Regents of the University of California. |
2 | .\" All rights reserved. The Berkeley software License Agreement | |
3 | .\" specifies the terms and conditions for redistribution. | |
4 | .\" | |
0e4a927e | 5 | .\" @(#)rename.2 6.1 (Berkeley) %G% |
786fe04f | 6 | .\" |
0e4a927e | 7 | .TH RENAME 2 "" |
786fe04f KM |
8 | .UC 5 |
9 | .SH NAME | |
10 | rename \- change the name of a file | |
11 | .SH SYNOPSIS | |
12 | .ft B | |
13 | .nf | |
14 | rename(from, to) | |
15 | char *from, *to; | |
16 | .fi | |
17 | .ft R | |
18 | .SH DESCRIPTION | |
19 | .I Rename | |
20 | causes the link named | |
21 | .I from | |
22 | to be renamed as | |
23 | .IR to . | |
24 | If | |
25 | .I to | |
26 | exists, then it is first removed. | |
27 | Both | |
28 | .I from | |
29 | and | |
30 | .I to | |
31 | must be of the same type (that is, both directories or both | |
32 | non-directories), and must reside on the same file system. | |
33 | .PP | |
34 | .I Rename | |
35 | guarantees that an instance of | |
36 | .I to | |
37 | will always exist, even if the system should crash in | |
38 | the middle of the operation. | |
39 | .SH CAVEAT | |
40 | The system can deadlock if a loop in the file system graph is present. | |
41 | This loop takes the form of an entry in directory \*(lqa\*(rq, | |
42 | say \*(lqa/foo\*(rq, | |
43 | being a hard link to directory \*(lqb\*(rq, and an entry in | |
44 | directory \*(lqb\*(rq, say \*(lqb/bar\*(rq, being a hard link | |
45 | to directory \*(lqa\*(rq. | |
46 | When such a loop exists and two separate processes attempt to | |
47 | perform \*(lqrename a/foo b/bar\*(rq and \*(lqrename b/bar a/foo\*(rq, | |
48 | respectively, | |
49 | the system may deadlock attempting to lock | |
50 | both directories for modification. | |
51 | Hard links to directories should be | |
52 | replaced by symbolic links by the system administrator. | |
53 | .SH "RETURN VALUE" | |
54 | A 0 value is returned if the operation succeeds, otherwise | |
55 | .I rename | |
56 | returns \-1 and the global variable | |
57 | .I errno | |
58 | indicates the reason for the failure. | |
59 | .SH "ERRORS | |
60 | .I Rename | |
61 | will fail and neither of the argument files will be | |
62 | affected if any of the following are true: | |
63 | .TP 15 | |
64 | [ENOTDIR] | |
65 | A component of either path prefix is not a directory. | |
66 | .TP 15 | |
67 | [ENOENT] | |
68 | A component of either path prefix does not exist. | |
69 | .TP 15 | |
70 | [EACCES] | |
71 | A component of either path prefix denies search permission. | |
72 | .TP 15 | |
73 | [ENOENT] | |
74 | The file named by \fIfrom\fP does not exist. | |
75 | .TP 15 | |
76 | [EPERM] | |
77 | The file named by \fIfrom\fP is a directory and the effective | |
78 | user ID is not super-user. | |
79 | .TP 15 | |
80 | [EXDEV] | |
81 | The link named by \fIto\fP and the file named by \fIfrom\fP | |
82 | are on different logical devices (file systems). Note that this error | |
83 | code will not be returned if the implementation permits cross-device | |
84 | links. | |
85 | .TP 15 | |
86 | [EACCES] | |
87 | The requested link requires writing in a directory with a mode | |
88 | that denies write permission. | |
89 | .TP 15 | |
90 | [EROFS] | |
91 | The requested link requires writing in a directory on a read-only file | |
92 | system. | |
93 | .TP 15 | |
94 | [EFAULT] | |
95 | .I Path | |
96 | points outside the process's allocated address space. | |
97 | .TP 15 | |
98 | [EINVAL] | |
99 | .I From | |
100 | is a parent directory of | |
101 | .IR to . | |
102 | .SH "SEE ALSO" | |
103 | open(2) |