xref: /dragonfly/lib/libc/sys/unlink.2 (revision 0db87cb7)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     @(#)unlink.2	8.1 (Berkeley) 6/4/93
29.\" $FreeBSD: src/lib/libc/sys/unlink.2,v 1.8.2.4 2001/12/14 18:34:02 ru Exp $
30.\" $DragonFly: src/lib/libc/sys/unlink.2,v 1.4 2007/04/26 17:35:03 swildner Exp $
31.\"
32.Dd August 18, 2009
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.Fa path
60may not be a directory.
61.Sh RETURN VALUES
62.Rv -std unlink
63.Sh ERRORS
64The
65.Fn unlink
66succeeds unless:
67.Bl -tag -width Er
68.It Bq Er ENOTDIR
69A component of the path prefix is not a directory.
70.It Bq Er ENAMETOOLONG
71A component of a pathname exceeded 255 characters,
72or an entire path name exceeded 1023 characters.
73.It Bq Er ENOENT
74The named file does not exist.
75.It Bq Er EACCES
76Search permission is denied for a component of the path prefix.
77.It Bq Er EACCES
78Write permission is denied on the directory containing the link
79to be removed.
80.It Bq Er ELOOP
81Too many symbolic links were encountered in translating the pathname.
82.It Bq Er EPERM
83The named file has its immutable or append-only flag set (see
84.Xr chflags 2 ) .
85.It Bq Er EPERM
86The named file is a directory.
87.It Bq Er EPERM
88The directory containing the file is marked sticky,
89and neither the containing directory nor the file to be removed
90are owned by the effective user ID.
91.It Bq Er EBUSY
92The entry to be unlinked is the mount point for a
93mounted file system.
94.It Bq Er EIO
95An I/O error occurred while deleting the directory entry
96or deallocating the inode.
97.It Bq Er EROFS
98The named file resides on a read-only file system.
99.It Bq Er EFAULT
100.Fa Path
101points outside the process's allocated address space.
102.El
103.Sh SEE ALSO
104.Xr close 2 ,
105.Xr link 2 ,
106.Xr rmdir 2 ,
107.Xr unlinkat 2 ,
108.Xr symlink 7
109.Sh HISTORY
110An
111.Fn unlink
112function call appeared in
113.At v6 .
114.Pp
115The
116.Fn unlink
117system call traditionally allows the super-user to unlink directories which
118can damage the filesystem integrity.  This implementation no longer permits
119it.
120