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