xref: /netbsd-src/lib/libc/sys/unlink.2 (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1.\"	$NetBSD: unlink.2,v 1.23 2010/05/31 12:16:20 njoly 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. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)unlink.2	8.1 (Berkeley) 6/4/93
31.\"
32.Dd April 3, 2010
33.Dt UNLINK 2
34.Os
35.Sh NAME
36.Nm unlink
37.Nd remove directory entry
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In unistd.h
42.Ft int
43.Fn unlink "const char *path"
44.Sh DESCRIPTION
45The
46.Fn unlink
47function
48removes the link named by
49.Fa path
50from its directory and decrements the link count of the
51file which was referenced by the link.
52If that decrement reduces the link count of the file
53to zero,
54and no process has the file open, then
55all resources associated with the file are reclaimed.
56If one or more process have the file open when the last link is removed,
57the link is removed, but the removal of the file is delayed until
58all references to it have been closed.
59.Sh RETURN VALUES
60Upon successful completion, a value of 0 is returned.
61Otherwise, a value of \-1 is returned and
62.Va errno
63is set to indicate the error.
64.Sh ERRORS
65The
66.Fn unlink
67succeeds unless:
68.Bl -tag -width Er
69.It Bq Er EACCES
70Search permission is denied for a component of the path prefix, or
71write permission is denied on the directory containing the link
72to be removed.
73.It Bq Er EBUSY
74The entry to be unlinked is the mount point for a
75mounted file system.
76.It Bq Er EFAULT
77.Fa path
78points outside the process's allocated address space.
79.It Bq Er EIO
80An I/O error occurred while deleting the directory entry
81or deallocating the inode.
82.It Bq Er ELOOP
83Too many symbolic links were encountered in translating the pathname.
84.It Bq Er ENAMETOOLONG
85A component of a pathname exceeded
86.Brq Dv NAME_MAX
87characters, or an entire path name exceeded
88.Brq Dv PATH_MAX
89characters.
90.It Bq Er ENOENT
91The named file does not exist.
92.It Bq Er ENOTDIR
93A component of the path prefix is not a directory.
94.It Bq Er EPERM
95The named file is a directory and the effective user ID
96of the process is not the super-user, the file system
97containing the file does not permit the use of
98.Fn unlink
99on a directory,
100or the directory containing the file is marked sticky,
101and neither the containing directory nor the file to be removed
102are owned by the effective user ID.
103.It Bq Er EROFS
104The named file resides on a read-only file system.
105.El
106.Sh SEE ALSO
107.Xr close 2 ,
108.Xr link 2 ,
109.Xr rmdir 2 ,
110.Xr symlink 7
111.Sh STANDARDS
112The
113.Fn unlink
114function conforms to
115.St -p1003.1-90 .
116.Sh HISTORY
117An
118.Fn unlink
119function call appeared in
120.At v2 .
121