ksh: build with __EXTENSIONS__ to expose confstr
[unleashed.git] / share / man / man2 / mkdir.2
blob01fdc7ac43a77fcc46a6f34a1ec5b26534e42304
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 .\" Copyright (c) 2001, The IEEE and The Open Group.  All Rights Reserved.
45 .\" Copyright (c) 2007, Sun Microsystems, Inc.  All Rights Reserved.
46 .\" Copyright 2016 Joyent, Inc.
47 .\"
48 .TH MKDIR 2 "Sep 24, 2016"
49 .SH NAME
50 mkdir, mkdirat \- make a directory
51 .SH SYNOPSIS
52 .LP
53 .nf
54 #include <sys/types.h>
55 #include <sys/stat.h>
57 \fBint\fR \fBmkdir\fR(\fBconst char *\fR\fIpath\fR, \fBmode_t\fR \fImode\fR);
58 .fi
59 .LP
60 .nf
61 \fBint\fR \fBmkdirat\fR(\fBint\fR \fIfd\fR, \fBconst char *\fR\fIpath\fR, \fBmode_t\fR \fImode\fR);
62 .fi
64 .SH DESCRIPTION
65 .LP
66 The \fBmkdir()\fR and \fBmkdirat()\fR functions create a new directory named by
67 the path name pointed to by \fIpath\fR. The mode of the new directory is
68 initialized from \fImode\fR (see \fBchmod\fR(2) for values of mode). The
69 protection part of the \fImode\fR argument is modified by the process's file
70 creation mask (see \fBumask\fR(2)).
71 .sp
72 .LP
73 The directory's owner \fBID\fR is set to the process's effective user ID. The
74 directory's group \fBID\fR is set to the process's effective group ID, or if
75 the \fBS_ISGID\fR bit is set in the parent directory, then the group \fBID\fR
76 of the directory is inherited from the parent.  The \fBS_ISGID\fR bit of the
77 new directory is inherited from the parent directory.
78 .sp
79 .LP
80 If \fIpath\fR names a symbolic link, \fBmkdir()\fR and \fBmkdirat()\fR fail and
81 set errno to \fBEEXIST\fR.
82 .sp
83 .LP
84 The newly created directory is empty with the exception of entries for itself
85 (\fB\&.\fR) and its parent directory (\fB\&..\fR).
86 .sp
87 .LP
88 The \fBmkdirat()\fR function behaves similarly to \fBmkdir()\fR; however, if
89 \fIpath\fR is a relative path, then the directory represented by \fBfd\fR is
90 used as the starting point for resolving \fIpath\fR. To use the processes
91 current working directory, \fIfd\fR may be set to the value \fBAT_FDCWD\fR.
92 .sp
93 .LP
94 Upon successful completion, \fBmkdir()\fR and \fBmkdirat()\fR mark for update
95 the \fBst_atime\fR, \fBst_ctime\fR and \fBst_mtime\fR fields of the directory.
96 Also, the \fBst_ctime\fR and \fBst_mtime\fR fields of the directory that
97 contains the new entry are marked for update.
98 .SH RETURN VALUES
99 .LP
100 Upon successful completion, \fB0\fR is returned. Otherwise, \fB\(mi1\fR is
101 returned, no directory is created, and \fBerrno\fR is set to indicate the
102 error.
103 .SH ERRORS
105 The \fBmkdir()\fR and \fBmkdirat()\fR functions will fail if:
107 .ne 2
109 \fB\fBEACCES\fR\fR
111 .RS 16n
112 Either a component of the path prefix denies search permission or write
113 permission is denied on the parent directory of the directory to be created.
117 .ne 2
119 \fB\fBEDQUOT\fR\fR
121 .RS 16n
122 The directory where the new file entry is being placed cannot be extended
123 because the user's quota of disk blocks on that file system has been exhausted;
124 the new directory cannot be created because the user's quota of disk blocks on
125 that file system has been exhausted; or the user's quota of inodes on the file
126 system where the file is being created has been exhausted.
130 .ne 2
132 \fB\fBEEXIST\fR\fR
134 .RS 16n
135 The named file already exists.
139 .ne 2
141 \fB\fBEFAULT\fR\fR
143 .RS 16n
144 The \fIpath\fR argument points to an illegal address.
148 .ne 2
150 \fB\fBEINVAL\fR\fR
152 .RS 16n
153 An attempt was made to create an extended attribute that is a directory.
157 .ne 2
159 \fB\fBEIO\fR\fR
161 .RS 16n
162 An I/O error has occurred while accessing the file system.
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\fBELOOP\fR\fR
180 .RS 16n
181 Too many symbolic links were encountered in translating \fIpath\fR, or a loop
182 exists in symbolic links encountered during resolution of \fIpath\fR
186 .ne 2
188 \fB\fBEMLINK\fR\fR
190 .RS 16n
191 The maximum number of links to the parent directory would be exceeded.
195 .ne 2
197 \fB\fBENAMETOOLONG\fR\fR
199 .RS 16n
200 The length of the \fIpath\fR argument exceeds \fBPATH_MAX\fR, or the length of
201 a \fIpath\fR component exceeds \fBNAME_MAX\fR while \fB_POSIX_NO_TRUNC\fR is in
202 effect.
206 .ne 2
208 \fB\fBENOENT\fR\fR
210 .RS 16n
211 A component of the path prefix does not exist or is a null pathname.
215 .ne 2
217 \fB\fBENOLINK\fR\fR
219 .RS 16n
220 The \fIpath\fR argument points to a remote machine and the link to that machine
221 is no longer active.
225 .ne 2
227 \fB\fBENOSPC\fR\fR
229 .RS 16n
230 No free space is available on the device containing the directory.
234 .ne 2
236 \fB\fBENOTDIR\fR\fR
238 .RS 16n
239 A component of the path prefix is not a directory. For \fBlinkat()\fR, if
240 \fIpath\fR is a relative path and \fIfd\fR refers to a valid file descriptor
241 which is not a directory.
245 .ne 2
247 \fB\fBEROFS\fR\fR
249 .RS 16n
250 The path prefix resides on a read-only file system.
255 The \fBmkdirat()\fR function will fail if:
257 .ne 2
259 .B EBADF
261 .RS 16n
262 The path \fIpath\fR is a relative path and \fIfd\fR is not a valid open file
263 descriptor or the value \fBAT_FDCWD\fR.
268 The \fBmkdir()\fR function may fail if:
270 .ne 2
272 \fB\fBENAMETOOLONG\fR\fR
274 .RS 16n
275 As a result of encountering a symbolic link in resolution of the \fIpath\fR
276 argument, the length of the substituted pathname string exceeded
277 {\fBPATH_MAX\fR}.
280 .SH EXAMPLES
282 \fBExample 1 \fRCreate a directory.
285 The following example demonstrates how to create a directory named
286 \fB/home/cnd/mod1\fR, with read, write, and search permissions for owner and
287 group, and with read and search permissions for others.
290 .in +2
292 #include <sys/types.h>
293 #include <sys/stat.h>
294 int status;
295 \&...
296 status = mkdir("/home/cnd/mod1",
297      S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
299 .in -2
301 .SH ATTRIBUTES
303 See \fBattributes\fR(5) for descriptions of the following attributes:
308 box;
309 c | c
310 l | l .
311 ATTRIBUTE TYPE  ATTRIBUTE VALUE
313 Interface Stability     Standard
315 MT-Level        Async-Signal-Safe
318 .SH SEE ALSO
320 \fBchmod\fR(2), \fBmknod\fR(2), \fBumask\fR(2), \fBmkdirp\fR(3GEN),
321 \fBstat.h\fR(3HEAD), \fBattributes\fR(5), \fBstandards\fR(5)