1*61186Sbostic.\" Copyright (c) 1980, 1991, 1993 2*61186Sbostic.\" The Regents of the University of California. All rights reserved. 320098Smckusick.\" 447208Scael.\" %sccs.include.redist.man% 520098Smckusick.\" 6*61186Sbostic.\" @(#)unlink.2 8.1 (Berkeley) 06/04/93 747208Scael.\" 847208Scael.Dd 947208Scael.Dt UNLINK 2 1047208Scael.Os BSD 4 1147208Scael.Sh NAME 1247208Scael.Nm unlink 1347208Scael.Nd remove directory entry 1447208Scael.Sh SYNOPSIS 1547208Scael.Fd #include <unistd.h> 1647208Scael.Ft int 1747208Scael.Fn unlink "const char *path" 1847208Scael.Sh DESCRIPTION 1947208ScaelThe 2047208Scael.Fn unlink 2147208Scaelfunction 2247208Scaelremoves the link named by 2347208Scael.Fa path 2447208Scaelfrom its directory and decrements the link count of the 2547208Scaelfile which was referenced by the link. 2647208ScaelIf that decrement reduces the link count of the file 2747208Scaelto zero, 2820099Smckusickand no process has the file open, then 2920099Smckusickall resources associated with the file are reclaimed. 3047208ScaelIf one or more process have the file open when the last link is removed, 3147208Scaelthe link is removed, but the removal of the file is delayed until 3247208Scaelall references to it have been closed. 3347208Scael.Sh RETURN VALUES 3420099SmckusickUpon successful completion, a value of 0 is returned. 3547208ScaelOtherwise, a value of -1 is returned and 3647208Scael.Va errno 3720099Smckusickis set to indicate the error. 3847208Scael.Sh ERRORS 3947208ScaelThe 4047208Scael.Fn unlink 4147208Scaelsucceeds unless: 4247208Scael.Bl -tag -width ENAMETOOLONGAA 4347208Scael.It Bq Er ENOTDIR 4420099SmckusickA component of the path prefix is not a directory. 4547208Scael.It Bq Er EINVAL 4621003SmckusickThe pathname contains a character with the high-order bit set. 4747208Scael.It Bq Er ENAMETOOLONG 4821003SmckusickA component of a pathname exceeded 255 characters, 4921003Smckusickor an entire path name exceeded 1023 characters. 5047208Scael.It Bq Er ENOENT 5120099SmckusickThe named file does not exist. 5247208Scael.It Bq Er EACCES 5320099SmckusickSearch permission is denied for a component of the path prefix. 5447208Scael.It Bq Er EACCES 5520099SmckusickWrite permission is denied on the directory containing the link 5620099Smckusickto be removed. 5747208Scael.It Bq Er ELOOP 5821003SmckusickToo many symbolic links were encountered in translating the pathname. 5947208Scael.It Bq Er EPERM 6020099SmckusickThe named file is a directory and the effective user ID 6120099Smckusickof the process is not the super-user. 6247208Scael.It Bq Er EPERM 6321003SmckusickThe directory containing the file is marked sticky, 6421003Smckusickand neither the containing directory nor the file to be removed 6521003Smckusickare owned by the effective user ID. 6647208Scael.It Bq Er EBUSY 6720099SmckusickThe entry to be unlinked is the mount point for a 6820099Smckusickmounted file system. 6947208Scael.It Bq Er EIO 7021003SmckusickAn I/O error occurred while deleting the directory entry 7121003Smckusickor deallocating the inode. 7247208Scael.It Bq Er EROFS 7320099SmckusickThe named file resides on a read-only file system. 7447208Scael.It Bq Er EFAULT 7547208Scael.Fa Path 7620099Smckusickpoints outside the process's allocated address space. 7747208Scael.El 7847208Scael.Sh SEE ALSO 7947208Scael.Xr close 2 , 8047208Scael.Xr link 2 , 8147208Scael.Xr rmdir 2 8255727Sbostic.Xr symlink 7 8347208Scael.Sh HISTORY 8447208ScaelAn 8547208Scael.Nm 8647208Scaelfunction call appeared in Version 6 AT&T UNIX. 87