]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/unlink.2
xnu-3789.1.32.tar.gz
[apple/xnu.git] / bsd / man / man2 / unlink.2
CommitLineData
9bccf70c
A
1.\" $NetBSD: unlink.2,v 1.7 1995/02/27 12:39:13 cgd Exp $
2.\"
3.\" Copyright (c) 1980, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\" @(#)unlink.2 8.1 (Berkeley) 6/4/93
35.\"
36.Dd June 4, 1993
37.Dt UNLINK 2
38.Os BSD 4
39.Sh NAME
fe8ab488
A
40.Nm unlink ,
41.Nm unlinkat
9bccf70c
A
42.Nd remove directory entry
43.Sh SYNOPSIS
44.Fd #include <unistd.h>
45.Ft int
2d21ac55
A
46.Fo unlink
47.Fa "const char *path"
48.Fc
fe8ab488
A
49.Ft int
50.Fn unlinkat "int fd" "const char *path" "int flag"
9bccf70c
A
51.Sh DESCRIPTION
52The
53.Fn unlink
54function
55removes the link named by
56.Fa path
57from its directory and decrements the link count of the
58file which was referenced by the link.
59If that decrement reduces the link count of the file
60to zero,
61and no process has the file open, then
62all resources associated with the file are reclaimed.
63If one or more process have the file open when the last link is removed,
64the link is removed, but the removal of the file is delayed until
65all references to it have been closed.
fe8ab488
A
66.Pp
67The
68.Fn unlinkat
69system call is equivalent to
70.Fn unlink
71or
72.Fn rmdir
73except in the case where
74.Fa path
75specifies a relative path.
76In this case the directory entry to be removed is determined
77relative to the directory associated with the file descriptor
78.Fa fd
79instead of the current working directory.
80.Pp
81The values for
82.Fa flag
83are constructed by a bitwise-inclusive OR of flags from the following list,
84defined in
85.In fcntl.h :
86.Bl -tag -width indent
87.It Dv AT_REMOVEDIR
88Remove the directory entry specified by
89.Fa fd
90and
91.Fa path
92as a directory, not a normal file.
93.El
94.Pp
95If
96.Fn unlinkat
97is passed the special value
98.Dv AT_FDCWD
99in the
100.Fa fd
101parameter, the current working directory is used and the behavior is
102identical to a call to
103.Fa unlink
104or
105.Fa rmdir
106respectively, depending on whether or not the
107.Dv AT_REMOVEDIR
108bit is set in flag.
9bccf70c
A
109.Sh RETURN VALUES
110Upon successful completion, a value of 0 is returned.
111Otherwise, a value of -1 is returned and
112.Va errno
113is set to indicate the error.
114.Sh ERRORS
115The
116.Fn unlink
2d21ac55 117system call will fail if:
9bccf70c 118.Bl -tag -width Er
2d21ac55 119.\" ===========
9bccf70c
A
120.It Bq Er EACCES
121Search permission is denied for a component of the path prefix.
2d21ac55 122.\" ===========
9bccf70c
A
123.It Bq Er EACCES
124Write permission is denied on the directory containing the link
125to be removed.
2d21ac55
A
126.\" ===========
127.It Bq Er EBUSY
128The entry to be unlinked is the mount point for a
129mounted file system.
130.\" ===========
131.It Bq Er EBUSY
132The file named by the
133.Fa path
134argument cannot be unlinked
135because it is being used by the system or by another process.
136.\" ===========
137.It Bq Er EFAULT
138.Fa Path
139points outside the process's allocated address space.
140.\" ===========
141.It Bq Er EIO
142An I/O error occurs while deleting the directory entry
143or deallocating the inode.
144.\" ===========
9bccf70c 145.It Bq Er ELOOP
2d21ac55
A
146Too many symbolic links are encountered in translating the pathname.
147This is taken to be indicative of a looping symbolic link.
148.\" ===========
149.It Bq Er ENAMETOOLONG
150A component of a pathname exceeds
151.Dv {NAME_MAX}
152characters, or an entire path name exceeds
153.Dv {PATH_MAX}
154characters (possibly as a result of expanding a symlink).
155.\" ===========
156.It Bq Er ENOENT
157The named file does not exist.
158.\" ===========
159.It Bq Er ENOTDIR
160A component of the path prefix is not a directory.
161.\" ===========
9bccf70c
A
162.It Bq Er EPERM
163The named file is a directory and the effective user ID
164of the process is not the super-user.
2d21ac55 165.\" ===========
9bccf70c
A
166.It Bq Er EPERM
167The directory containing the file is marked sticky,
168and neither the containing directory nor the file to be removed
169are owned by the effective user ID.
2d21ac55 170.\" ===========
9bccf70c
A
171.It Bq Er EROFS
172The named file resides on a read-only file system.
9bccf70c 173.El
fe8ab488
A
174.Pp
175In addition to the errors returned by the
176.Fn unlink ,
177the
178.Fn unlinkat
179may fail if:
180.Bl -tag -width Er
181.It Bq Er EBADF
182The
183.Fa path
184argument does not specify an absolute path and the
185.Fa fd
186argument is neither
187.Dv AT_FDCWD
188nor a valid file descriptor open for searching.
189.It Bq Er ENOTEMPTY
190The
191.Fa flag
192parameter has the
193.Dv AT_REMOVEDIR
194bit set and the
195.Fa path
196argument names a directory that is not an empty directory,
197or there are hard links to the directory other than dot or
198a single entry in dot-dot.
199.It Bq Er ENOTDIR
200The
201.Fa flag
202parameter has the
203.Dv AT_REMOVEDIR
204bit set and
205.Fa path
206does not name a directory.
207.It Bq Er EINVAL
208The value of the
209.Fa flag
210argument is not valid.
211.It Bq Er ENOTDIR
212The
213.Fa path
214argument is not an absolute path and
215.Fa fd
216is neither
217.Dv AT_FDCWD
218nor a file descriptor associated with a directory.
219.El
9bccf70c
A
220.Sh SEE ALSO
221.Xr close 2 ,
222.Xr link 2 ,
2d21ac55 223.Xr rmdir 2 ,
9bccf70c 224.Xr symlink 7
fe8ab488
A
225.Sh STANDARDS
226The
227.Fn unlinkat
228system call is expected to conform to POSIX.1-2008 .
9bccf70c
A
229.Sh HISTORY
230An
231.Fn unlink
232function call appeared in
233.At v6 .
fe8ab488
A
234The
235.Fn unlinkat
236system call appeared in OS X 10.10