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