'\"macro stdmacro
.if n .pH g2.unlink @(#)unlink	40.21 of 10/10/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} unlink 2 "" "\&"
.if \nX=1 .ds x} unlink 2 ""
.if \nX=2 .ds x} unlink 2 "" "\&"
.if \nX=3 .ds x} unlink "" "" "\&"
.TH \*(x}
.SH NAME
\f4unlink\f1 \- remove directory entry
.SH SYNOPSIS
\f4#include <unistd.h>\f1
.PP
\f4int unlink(const char \(**path);\f1
.SH DESCRIPTION
\f4unlink\f1
removes the directory entry named by the
path name
pointed to by
\f2path\f1.
and decrements the link count of the file referenced by the
directory entry.
When all links to a file have been removed and no process has the file open,
the space occupied by the file is freed and the file ceases to exist.
If one or more processes have the file open when the last link is removed,
space occupied by the file is not released until all references to the file
have been closed.
If \f2path\f1 is a symbolic link, the symbolic link is removed.
\f2path\f1 should not name a directory unless the
process has appropriate privileges.
Applications
should use \f4rmdir\f1 to remove directories.
.P
Upon successful completion \f4unlink\f1 marks for update the
\f4st_ctime\f1 and \f4st_mtime\f1 fields of the parent directory. Also, if
the file's link count is not zero, the \f4st_ctime\f1 field of the file is
marked for update.
.PP
The named file is unlinked unless one or more of the following are true:
.TP 20
\f4EACCES\f1
Search permission is denied for a component of the
\f2path\f1
prefix.
.TP
\f4EACCES\f1
Write permission is denied on the directory containing the link
to be removed.
.TP
\f4EACCES\f1
The parent directory has the sticky bit set and
the file is not writable by the user;
the user does not own the parent directory and
the user does not own the file;
.TP
\f4EBUSY\f1
The entry to be unlinked is the mount point for a mounted file system.
.TP
\f4EFAULT\f1
\f2path\f1
points outside the process's allocated address space.
.TP
\f4EINTR\f1
A signal was caught during the \f4unlink\f1 system call.
.TP
\f4ELOOP\f1
Too many symbolic links were encountered in translating \f2path\f1.
.TP
\f4EMULTIHOP\f1
Components of \f2path\f1 require hopping to multiple
remote machines
and the file system does not allow it.
.TP
\f4ENAMETOOLONG\f1
The length of the \f2path\f1 argument exceeds {\f4PATH_MAX\f1}, or the
length of a \f2path\f1 component exceeds {\f4NAME_MAX\f1} while
\f4_POSIX_NO_TRUNC\f1 is in effect.
.TP
\f4ENOENT\f1
The named file does not exist or is a null pathname.
The user is not a super-user.
.TP
\f4ENOTDIR\f1
A component of the
\f2path\f1
prefix
is not a directory.
.TP
\f4EPERM\f1
The named file is a directory and the effective user ID
of the process is
not super-user.
.TP
\f4ETXTBSY\f1
The entry to be unlinked is
the last link to
a pure procedure (shared text) file
that is being executed.
.TP
\f4EROFS\f1
The directory entry to be unlinked is part of a
read-only file system.
.TP
\f4ENOLINK\f1
\f2path\f1 points to a remote machine and the link
to that machine is no longer active.
.SH "SEE ALSO"
\f4close\f1(2), \f4link\f1(2), \f4open\f1(2), \f4rmdir\f1(2).
.br
\f4rm\f1(1)
in the
\f2User's Reference Manual\f1.
.SH "DIAGNOSTICS"
Upon successful completion, a value of 0 is returned.
Otherwise, a value of \-1 is returned and
\f4errno\fP
is set to indicate the error.
.\"	@(#)unlink.2	6.2 of 9/6/83
.Ee
