1 '\" te
   2 .\" Copyright (c) 2007, Sun Microsystems, Inc.  All Rights Reserved.
   3 .\" Copyright 1989 AT&T
   4 .\" Portions Copyright (c) 1992, X/Open Company Limited  All Rights Reserved.
   5 .\" Copyright 2016 RackTop Systems.
   6 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
   7 .\" http://www.opengroup.org/bookstore/.
   8 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
   9 .\"  This notice shall appear on any product containing this material.
  10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
  11 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
  12 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
  13 .TH UNLINK 2 "Dec 15, 2016"
  14 .SH NAME
  15 unlink, unlinkat \- remove directory entry
  16 .SH SYNOPSIS
  17 .LP
  18 .nf
  19 #include <unistd.h>
  20 
  21 \fBint\fR \fBunlink\fR(\fBconst char *\fR\fIpath\fR);
  22 .fi
  23 
  24 .LP
  25 .nf
  26 \fBint\fR \fBunlinkat\fR(\fBint\fR \fIdirfd\fR, \fBconst char *\fR\fIpath\fR, \fBint\fR \fIflag\fR);
  27 .fi
  28 
  29 .SH DESCRIPTION
  30 .sp
  31 .LP
  32 The \fBunlink()\fR function removes a link to a file. If \fIpath\fR names a
  33 symbolic link, \fBunlink()\fR removes the symbolic link named by \fIpath\fR and
  34 does not affect any file or directory named by the contents of the symbolic
  35 link.  Otherwise, \fBunlink()\fR removes the link named by the pathname pointed
  36 to by \fIpath\fR and decrements the link count of the file referenced by the
  37 link.
  38 .sp
  39 .LP
  40 The \fBunlinkat()\fR function also removes a link to a file. See
  41 \fBfsattr\fR(5). If the \fIflag\fR argument is 0, the behavior of
  42 \fBunlinkat()\fR is the same as \fBunlink()\fR except in the processing of its
  43 \fIpath\fR argument. If \fIpath\fR is absolute, \fBunlinkat()\fR behaves the
  44 same as \fBunlink()\fR and the \fIdirfd\fR argument is unused. If \fIpath\fR is
  45 relative and \fIdirfd\fR has the value \fBAT_FDCWD\fR, defined in
  46 <\fBfcntl.h\fR>, \fBunlinkat()\fR also behaves the same as \fBunlink()\fR.
  47 Otherwise, \fIpath\fR is resolved relative to the directory referenced by the
  48 \fIdirfd\fR argument.
  49 .sp
  50 .LP
  51 If the \fIflag\fR argument is set to the value \fBAT_REMOVEDIR\fR, defined in
  52 <\fBfcntl.h\fR>, \fBunlinkat()\fR behaves the same as \fBrmdir\fR(2) except in
  53 the processing of the \fIpath\fR argument as described above.
  54 .sp
  55 .LP
  56 When the file's link count becomes 0 and no process has the file open, the
  57 space occupied by the file will be freed and the file is no longer accessible.
  58 If one or more processes have the file open when the last link is removed, the
  59 link is removed before \fBunlink()\fR or \fBunlinkat()\fR returns, but the
  60 removal of the file contents is postponed until all references to the file are
  61 closed.
  62 .sp
  63 .LP
  64 If the \fIpath\fR argument is a directory and the filesystem supports
  65 \fBunlink()\fR and \fBunlinkat()\fR on directories the behaviour is dependent
  66 on the filesystem.
  67 .sp
  68 .LP
  69 If the \fIpath\fR argument is a directory and the filesystem does not support
  70 \fBunlink()\fR and \fBunlink()\fR on directories (for example, ZFS), the call
  71 will fail with \fBerrno\fR set to \fBEPERM\fR.
  72 .sp
  73 .LP
  74 Upon successful completion, \fBunlink()\fR and \fBunlinkat()\fR will mark for
  75 update the \fBst_ctime\fR and \fBst_mtime\fR fields of the parent directory.
  76 If the file's link count is not 0, the \fBst_ctime\fR field of the file will be
  77 marked for update.
  78 .SH RETURN VALUES
  79 .sp
  80 .LP
  81 Upon successful completion, \fB0\fR is returned.  Otherwise, \fB\(mi1\fR is
  82 returned, \fBerrno\fR is set to indicate the error, and the file is not
  83 unlinked.
  84 .SH ERRORS
  85 .sp
  86 .LP
  87 The \fBunlink()\fR and \fBunlinkat()\fR functions will fail if:
  88 .sp
  89 .ne 2
  90 .na
  91 \fB\fBEACCES\fR\fR
  92 .ad
  93 .RS 16n
  94 Search permission is denied for a component of the \fIpath\fR prefix, or write
  95 permission is denied on the directory containing the link to be removed.
  96 .RE
  97 
  98 .sp
  99 .ne 2
 100 .na
 101 \fB\fBEACCES\fR\fR
 102 .ad
 103 .RS 16n
 104 The parent directory has the sticky bit set and the file is not writable by the
 105 user, the user does not own the parent directory, the user does not own the
 106 file, and the user is not a privileged user.
 107 .RE
 108 
 109 .sp
 110 .ne 2
 111 .na
 112 \fB\fBEBUSY\fR\fR
 113 .ad
 114 .RS 16n
 115 The entry to be unlinked is the mount point for a mounted file system.
 116 .RE
 117 
 118 .sp
 119 .ne 2
 120 .na
 121 \fB\fBEFAULT\fR\fR
 122 .ad
 123 .RS 16n
 124 The \fIpath\fR argument points to an illegal address.
 125 .RE
 126 
 127 .sp
 128 .ne 2
 129 .na
 130 \fB\fBEILSEQ\fR\fR
 131 .ad
 132 .RS 16n
 133 The path argument includes non-UTF8 characters and the file system accepts only
 134 file names where all characters are part of the UTF-8 character codeset.
 135 .RE
 136 
 137 .sp
 138 .ne 2
 139 .na
 140 \fB\fBEINTR\fR\fR
 141 .ad
 142 .RS 16n
 143 A signal was caught during the execution of the \fBunlink()\fR function.
 144 .RE
 145 
 146 .sp
 147 .ne 2
 148 .na
 149 \fB\fBELOOP\fR\fR
 150 .ad
 151 .RS 16n
 152 Too many symbolic links were encountered in translating \fIpath\fR.
 153 .RE
 154 
 155 .sp
 156 .ne 2
 157 .na
 158 \fB\fBENAMETOOLONG\fR\fR
 159 .ad
 160 .RS 16n
 161 The length of the \fIpath\fR argument exceeds \fBPATH_MAX\fR, or the length of
 162 a \fIpath\fR component exceeds \fBNAME_MAX\fR while \fB_POSIX_NO_TRUNC\fR is in
 163 effect.
 164 .RE
 165 
 166 .sp
 167 .ne 2
 168 .na
 169 \fB\fBENOENT\fR\fR
 170 .ad
 171 .RS 16n
 172 The named file does not exist or is a null pathname.
 173 .RE
 174 
 175 .sp
 176 .ne 2
 177 .na
 178 \fB\fBENOLINK\fR\fR
 179 .ad
 180 .RS 16n
 181 The \fIpath\fR argument points to a remote machine and the link to that machine
 182 is no longer active.
 183 .RE
 184 
 185 .sp
 186 .ne 2
 187 .na
 188 \fB\fBENOTDIR\fR\fR
 189 .ad
 190 .RS 16n
 191 A component of the \fIpath\fR prefix is not a directory or the provided
 192 directory descriptor for \fBunlinkat()\fR is not \fBAT_FDCWD\fR or does not
 193 reference a directory.
 194 .RE
 195 
 196 .sp
 197 .ne 2
 198 .na
 199 \fB\fBEPERM\fR\fR
 200 .ad
 201 .RS 16n
 202 The named file is a directory and {\fBPRIV_SYS_LINKDIR\fR} is not asserted in
 203 the effective set of the calling process, or the filesystem implementation does
 204 not support \fBunlink()\fR or \fBunlinkat()\fR on directories.
 205 .RE
 206 
 207 .sp
 208 .ne 2
 209 .na
 210 \fB\fBEROFS\fR\fR
 211 .ad
 212 .RS 16n
 213 The directory entry to be unlinked is part of a read-only file system.
 214 .RE
 215 
 216 .sp
 217 .LP
 218 The \fBunlink()\fR and \fBunlinkat()\fR functions may fail if:
 219 .sp
 220 .ne 2
 221 .na
 222 \fB\fBENAMETOOLONG\fR\fR
 223 .ad
 224 .RS 16n
 225 Pathname resolution of a symbolic link produced an intermediate result whose
 226 length exceeds {\fBPATH_MAX\fR}.
 227 .RE
 228 
 229 .sp
 230 .ne 2
 231 .na
 232 \fB\fBETXTBSY\fR\fR
 233 .ad
 234 .RS 16n
 235 The entry to be unlinked is the last directory entry to a pure procedure
 236 (shared text) file that is being executed.
 237 .RE
 238 
 239 .SH USAGE
 240 .sp
 241 .LP
 242 Applications should use \fBrmdir\fR(2) to remove a directory.
 243 .SH ATTRIBUTES
 244 .sp
 245 .LP
 246 See \fBattributes\fR(5) for descriptions of the following attributes:
 247 .sp
 248 
 249 .sp
 250 .TS
 251 box;
 252 c | c
 253 l | l .
 254 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 255 _
 256 Interface Stability     T{
 257 \fBunlink()\fR is Standard; \fBunlinkat()\fR is Evolving
 258 T}
 259 _
 260 MT-Level        Async-Signal-Safe
 261 .TE
 262 
 263 .SH SEE ALSO
 264 .sp
 265 .LP
 266 \fBrm\fR(1), \fBclose\fR(2), \fBlink\fR(2), \fBopen\fR(2), \fBrmdir\fR(2),
 267 \fBremove\fR(3C), \fBattributes\fR(5), \fBprivileges\fR(5), \fBfsattr\fR(5)