xref: /netbsd-src/lib/libc/sys/unlink.2 (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1.\"	$NetBSD: unlink.2,v 1.20 2004/05/13 10:20:58 wiz 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 June 4, 1993
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 ENOTDIR
70A component of the path prefix is not a directory.
71.It Bq Er ENAMETOOLONG
72A component of a pathname exceeded
73.Dv {NAME_MAX}
74characters, or an entire path name exceeded
75.Dv {PATH_MAX}
76characters.
77.It Bq Er ENOENT
78The named file does not exist.
79.It Bq Er EACCES
80Search permission is denied for a component of the path prefix, or
81write permission is denied on the directory containing the link
82to be removed.
83.It Bq Er ELOOP
84Too many symbolic links were encountered in translating the pathname.
85.It Bq Er EPERM
86The named file is a directory and the effective user ID
87of the process is not the super-user, the file system
88containing the file does not permit the use of
89.Fn unlink
90on a directory,
91or the directory containing the file is marked sticky,
92and neither the containing directory nor the file to be removed
93are owned by the effective user ID.
94.It Bq Er EBUSY
95The entry to be unlinked is the mount point for a
96mounted file system.
97.It Bq Er EIO
98An I/O error occurred while deleting the directory entry
99or deallocating the inode.
100.It Bq Er EROFS
101The named file resides on a read-only file system.
102.It Bq Er EFAULT
103.Fa path
104points outside the process's allocated address space.
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 v6 .
121