1MKDIR(3P)                  POSIX Programmer's Manual                 MKDIR(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       mkdir - make a directory
13

SYNOPSIS

15       #include <sys/stat.h>
16
17       int mkdir(const char *path, mode_t mode);
18
19

DESCRIPTION

21       The mkdir() function shall create a new directory with name  path.  The
22       file  permission  bits  of  the new directory shall be initialized from
23       mode. These file permission bits of the mode argument shall be modified
24       by the process' file creation mask.
25
26       When  bits  in  mode  other  than the file permission bits are set, the
27       meaning of these additional bits is implementation-defined.
28
29       The directory's user ID shall be set to the process' effective user ID.
30       The  directory's  group  ID  shall be set to the group ID of the parent
31       directory or to the effective group ID of the process.  Implementations
32       shall provide a way to initialize the directory's group ID to the group
33       ID of the parent directory. Implementations may, but need not,  provide
34       an implementation-defined way to initialize the directory's group ID to
35       the effective group ID of the calling process.
36
37       The newly created directory shall be an empty directory.
38
39       If path names a symbolic link, mkdir() shall  fail  and  set  errno  to
40       [EEXIST].
41
42       Upon successful completion, mkdir() shall mark for update the st_atime,
43       st_ctime, and st_mtime fields of the directory. Also, the st_ctime  and
44       st_mtime  fields  of the directory that contains the new entry shall be
45       marked for update.
46

RETURN VALUE

48       Upon successful completion, mkdir() shall return 0. Otherwise, -1 shall
49       be  returned,  no directory shall be created, and errno shall be set to
50       indicate the error.
51

ERRORS

53       The mkdir() function shall fail if:
54
55       EACCES Search permission is denied on a component of the  path  prefix,
56              or  write  permission  is  denied on the parent directory of the
57              directory to be created.
58
59       EEXIST The named file exists.
60
61       ELOOP  A loop exists in symbolic links encountered during resolution of
62              the path argument.
63
64       EMLINK The link count of the parent directory would exceed {LINK_MAX}.
65
66       ENAMETOOLONG
67              The length of the path argument exceeds {PATH_MAX} or a pathname
68              component is longer than {NAME_MAX}.
69
70       ENOENT A component of the path prefix specified by path does  not  name
71              an existing directory or path is an empty string.
72
73       ENOSPC The  file  system does not contain enough space to hold the con‐
74              tents of the new directory or to extend the parent directory  of
75              the new directory.
76
77       ENOTDIR
78              A component of the path prefix is not a directory.
79
80       EROFS  The parent directory resides on a read-only file system.
81
82
83       The mkdir() function may fail if:
84
85       ELOOP  More  than  {SYMLOOP_MAX} symbolic links were encountered during
86              resolution of the path argument.
87
88       ENAMETOOLONG
89              As a result of encountering a symbolic link in resolution of the
90              path  argument,  the  length  of the substituted pathname string
91              exceeded {PATH_MAX}.
92
93
94       The following sections are informative.
95

EXAMPLES

97   Creating a Directory
98       The  following  example  shows  how  to  create   a   directory   named
99       /home/cnd/mod1, with read/write/search permissions for owner and group,
100       and with read/search permissions for others.
101
102
103              #include <sys/types.h>
104              #include <sys/stat.h>
105
106
107              int status;
108              ...
109              status = mkdir("/home/cnd/mod1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
110

APPLICATION USAGE

112       None.
113

RATIONALE

115       The mkdir() function originated in 4.2 BSD and was added to System V in
116       Release 3.0.
117
118       4.3 BSD detects [ENAMETOOLONG].
119
120       The POSIX.1-1990 standard required that the group ID of a newly created
121       directory be set to the group ID of its  parent  directory  or  to  the
122       effective  group  ID  of the creating process. FIPS 151-2 required that
123       implementations provide a way to have the group ID be set to the  group
124       ID  of  the  containing directory, but did not prohibit implementations
125       also supporting a way to set the group ID to the effective group ID  of
126       the  creating  process. Conforming applications should not assume which
127       group ID will be used. If it matters, an application can use chown() to
128       set  the  group  ID  after the directory is created, or determine under
129       what conditions the implementation will set the desired group ID.
130

FUTURE DIRECTIONS

132       None.
133

SEE ALSO

135       umask(),  the  Base   Definitions   volume   of   IEEE Std 1003.1-2001,
136       <sys/stat.h>, <sys/types.h>
137
139       Portions  of  this text are reprinted and reproduced in electronic form
140       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
141       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
142       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
143       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
144       event of any discrepancy between this version and the original IEEE and
145       The  Open Group Standard, the original IEEE and The Open Group Standard
146       is the referee document. The original Standard can be  obtained  online
147       at http://www.opengroup.org/unix/online.html .
148
149
150
151IEEE/The Open Group                  2003                            MKDIR(3P)
Impressum