1.\" Copyright (c) 1980, 1991 Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)unlink.2 6.4 (Berkeley) 07/27/92 7.\" 8.Dd 9.Dt UNLINK 2 10.Os BSD 4 11.Sh NAME 12.Nm unlink 13.Nd remove directory entry 14.Sh SYNOPSIS 15.Fd #include <unistd.h> 16.Ft int 17.Fn unlink "const char *path" 18.Sh DESCRIPTION 19The 20.Fn unlink 21function 22removes the link named by 23.Fa path 24from its directory and decrements the link count of the 25file which was referenced by the link. 26If that decrement reduces the link count of the file 27to zero, 28and no process has the file open, then 29all resources associated with the file are reclaimed. 30If one or more process have the file open when the last link is removed, 31the link is removed, but the removal of the file is delayed until 32all references to it have been closed. 33.Sh RETURN VALUES 34Upon successful completion, a value of 0 is returned. 35Otherwise, a value of -1 is returned and 36.Va errno 37is set to indicate the error. 38.Sh ERRORS 39The 40.Fn unlink 41succeeds unless: 42.Bl -tag -width ENAMETOOLONGAA 43.It Bq Er ENOTDIR 44A component of the path prefix is not a directory. 45.It Bq Er EINVAL 46The pathname contains a character with the high-order bit set. 47.It Bq Er ENAMETOOLONG 48A component of a pathname exceeded 255 characters, 49or an entire path name exceeded 1023 characters. 50.It Bq Er ENOENT 51The named file does not exist. 52.It Bq Er EACCES 53Search permission is denied for a component of the path prefix. 54.It Bq Er EACCES 55Write permission is denied on the directory containing the link 56to be removed. 57.It Bq Er ELOOP 58Too many symbolic links were encountered in translating the pathname. 59.It Bq Er EPERM 60The named file is a directory and the effective user ID 61of the process is not the super-user. 62.It Bq Er EPERM 63The directory containing the file is marked sticky, 64and neither the containing directory nor the file to be removed 65are owned by the effective user ID. 66.It Bq Er EBUSY 67The entry to be unlinked is the mount point for a 68mounted file system. 69.It Bq Er EIO 70An I/O error occurred while deleting the directory entry 71or deallocating the inode. 72.It Bq Er EROFS 73The named file resides on a read-only file system. 74.It Bq Er EFAULT 75.Fa Path 76points outside the process's allocated address space. 77.El 78.Sh SEE ALSO 79.Xr close 2 , 80.Xr link 2 , 81.Xr rmdir 2 82.Xr symlink 7 83.Sh HISTORY 84An 85.Nm 86function call appeared in Version 6 AT&T UNIX. 87