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