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